I have a form. where people fill in answers.
<form method="POST">
<input type="hidden" value="true" id="x" name="x">
<table>
<b>Do you use a Wheel impact and Load Detection System (ATLAS FO, former GOTCHA)?</b>
<hr />
<input type="hidden" value="Do you use a Wheel impact and Load Detection System (ATLAS FO, former GOTCHA)?" name="question1">
<tr>
<td><input type="radio" name="answer1" value="yes">Yes</td>
</tr>
<tr>
<td><input type="radio" name="answer1" value="no">No</td>
</tr>
</table>
<br /><br />
<table>
<b>Product Reliabillity:</b>
<hr />
<tr>
<input type="hidden" value="Product Reliabillity" name="question2">
<td><input type="radio" name="answer2" value="Very satisfied">Very satisfied</td>
<td><input type="radio" name="answer2" value="Satisfied">Satisfied</td>
<td><input type="radio" name="answer2" value="Less satified">Less satified</td>
<td><input type="radio" name="answer2" value="Very unsatisfied">Very unsatisfied</td>
<td><input type="radio" name="answer2" value="N/A">N/A</td>
</tr>
</table>
<br /><br />
<table>
<b>Product Handling:</b>
<hr />
<tr>
<input type="hidden" value="Product Handling" name="question3">
<td><input type="radio" name="answer3" value="Very satisfied">Very satisfied</td>
<td><input type="radio" name="answer3" value="Satisfied">Satisfied</td>
<td><input type="radio" name="answer3" value="Less satified">Less satified</td>
<td><input type="radio" name="answer3" value="Very unsatisfied">Very unsatisfied</td>
<td><input type="radio" name="answer3" value="N/A">N/A</td>
</tr>
</table>
<input type="submit" name="Add" value="submit">
<?php
if(isset($_POST['x'])){
$validcomment = false;
//validate check This should work but have not build in all the checks yet!!!!
if(!empty($_POST['answer2'])){
$validcomment = true;
}else{
echo "Please fill in all the questions!" . "<br>";
}
//If everything is okay, do this.
if($validcomment){
unset($_POST['x']);
echo $_POST['answer1'] . "<br />";
echo $_POST['answer2'] . "<br />";
echo $_POST['answer3'] . "<br />";
echo $_POST['answer4'] . "<br />";
echo $_POST['answer5'] . "<br />";
echo $_POST['answer6'] . "<br />" . "<br />";
echo $_POST['question1'] . "<br />";
echo $_POST['question2'] . "<br />";
echo $_POST['question3'] . "<br />";
echo $_POST['question4'] . "<br />";
echo $_POST['question5'] . "<br />";
echo $_POST['question6'] . "<br />";
}
}
?>
</form>
Now, this is showing me the results when i have inserted them. However, i would like to insert them in my database. My database looks like this:
(comment will be used later soo not important now.)
My current insert statement looks like this:
function enquete_insert() {
$sql = "INSERT INTO enquete "
. "(enquete_id, question, answer)"
. "VALUES (enquete_id, :question, :answer) ";
$sth = $this->pdo->prepare($sql);
$sth->bindParam(':question', $_POST['question'], PDO::PARAM_STR);
$sth->bindParam(':answer', $_POST['answer'], PDO::PARAM_STR);
$sth->execute();
}
This function is working when i name 1 of the question: question
and 1 of the answers answer
. also it only inserts 1 of the answers / questions then.
But i need it to add (in this example) 3 records in my database with the question, and answer.