0
我試圖獲得調查的回覆,所有問題的答案都顯示在while循環中並且在動作中PHP頁面我沒有得到正確的響應,我得到了正確的響應對於單選按鈕,我附上了代碼。在foreach循環中獲取多個表單輸入值
<?php
$i = 1;
while ($row = mysqli_fetch_array($questions)) {
?>
<div class="control-group">
<label class="control-label" for="focusedInput">(<?php echo $i; ?>)
<?php
$questionid = $row['question_id'];
$question = $row['question'];
?>
<input type="hidden" name="questionid" value="<?php echo $questionid; ?>" />
<input type="hidden" name="question" value="<?php echo $question; ?>" />
<?php echo $row['question']; ?></label>
<div class="controls">
<?php
if ($row['answer_type'] == "Ratings") {
echo "<p>
Low<input type='radio' name='rating$i' value='1' id='rating_0'>
<input type='radio' name='rating$i' value='2' id='rating_1'>
<input type='radio' name='rating$i' value='3' id='rating_2'>
<input type='radio' name='rating$i' value='4' id='rating_3'>
<input type='radio' name='rating$i' value='5' id='rating_4'>High
</p>";
} else if ($row['answer_type'] == "Comments") {
echo "<textarea name='answer' cols='' rows=''></textarea>";
}
$i++;
echo "<br />";
?>
</div>
</div>
<?php } ?>
行動文件代碼:
foreach($_POST as $val){
$query2 = "insert into review_details (review_id,survey_id,question_id,question,answer_rating,answer_freeresponse) values (1,$_SESSION[surveyid],$_POST[questionid],'$_POST[question]',$val,'$_POST[answer]')";
$result2 = mysqli_query($con,$query2);
if(!$result2) {
echo mysqli_error($result2);
}
}
我想插入在MySQL表包括在輸出圖像顯示領域的調查答案。
什麼結果你? – user3454436
你應該使用** mysqli_stmt_prepare()**。你不需要'foreach'。 – blue
結果在屏幕截圖中出現! @blue可以請你發佈相同的代碼片段! –