I am trying to make a poll system using php, mysql and ajax. I have created poll table from database.
id
answer
vote
I want users to increase their answers and i have created a simple javascript function like this DEMO
<div class="inputsl">
<div class="inputt"><input type="text" id="createPoll" name="mypoll" class="myinput"></div>
<div class="inputt"><input type="text" id="createPoll" name="mypoll" class="myinput"></div>
<div class="inputt"><input type="text" id="createPoll" name="mypoll" class="myinput"></div>
<div class="inputt"><input type="text" id="createPoll" name="mypoll" class="myinput"></div>
</div>
I have also created ajax function for inserting answers
$("body").on("click",".insertp", function(){
var poll = $("#createPoll").val();
var dataPoll = 'poll=' + poll;
$.ajax({
type:'POST',
url:'/requests/postPoll',
data: dataPoll,
cache: false,
beforeSend: function(){},
sucess: function(){
console.log("Success!");
}
});
});
and the postPoll.php functions
<?php
include_once '../inc/inc.php';
if(isset($_POST['poll'])){
$poll = mysqli_real_escape_string($db, $_POST['poll']);
if($poll){
foreach($poll as $setPoll){
$insertPollfromData = $InSert->Insert_Poll($uid, $setPoll);
}
}
}
?>
Now, i want to insert multiple answer from poll table but my postPoll.php gives me this error:
Warning: Invalid argument supplied for foreach() in
How can i insert multiple poll from database ? Anyone can help me here ? Thank you very much in advance for your help.
foreachwhen iterating overarrays. seems$pollis not an array but a boolean. Also where does$uidcome from?arraye.gcreate_answer[]and then iterate on your php side