Hello I am trying to make a survey using php and Mysql, with the code below I save every answer per questions, but When I tried to save comments_per_questions it did not save that field into the array it only save one comment.
How can I fix this function to save into the database Questions, Answers and Comments per questions?
Thanks in advance.
Database Structure
"Questions" (idquestion, question)
"Surveys" (idsurvey, idquestion, answers, comments_per_question, survey_number)
This part of code save the question and answers from the survey form.
public function NewSurveyMulti($answer = array())
{
if(!empty($answer)) {
foreach($answer as $questi => $value ) {
$this->MyDB->Write("INSERT INTO surveys (`idquestion`, `answers`,`comments_per_questions` )
VALUES(
'".$questi."',
'".$value[0]."',
'".$_POST["comment"]."')");
}
}
survey_form.php
<?php
// Fetch questions
$cuestionario = $con->Fetch("SELECT * FROM questions"); ?>
<form name="newDona" action="" method="post">
</table><?php
// Confirm there are questions being drawn from database
$numrows = (is_array($cuestionario))? count($cuestionario): 0;
if($numrows > 0) {
// Loop through questions
foreach($cuestionario as $row) { ?>
<tr>
<!-- Write the question -->
<td><?php echo $row["question"];?></td>
</tr>
<th>
<!-- Set the question id -->
<select name="answer[<?php echo $row['idquestion']; ?>][]">
<option value=""></option>
<option value="1">yes</option>
<option value="no">NO</option>
</select>
</th><?php
<th><textarea type="text" name="comment" maxlength="50" cols="130" rows="5"/ ></textarea></th>
} ?>
<tr>
<td colspan="5" align="center">
<input type="submit" name="send" id="send" value="SAVE" />
</td>
</tr>
</table>
</form>
<?php } ?>