我有一个包含四行的MySQL数据,每行代表一个问题和四个可能的答案。现在我想用四个答案显示每个问题作为单选按钮。我可以显示这些,但我很难在表单提交时获得用户选择的选项。
如何获取用户提交的值?
<?php
include 'db.php';
if (!empty($_POST)) {
// get the id_question and its value
}
?>
<form action="" method="post" enctype="multipart/form-data">
<?php
$sql ='select id_question, question,answer1,answer2,answer3,answer4 from prod_question_answers where id_product='.$_GET['id_product'];
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) { ?>
<h1>
<?php echo $row['question'] ?>
</h1>
<input name="<?php echo $row['id_question'] ?>" type="radio"value="<?php echo $row['answer1'] ?>"><?php echo $row['answer1'] ?>
<br>
<input name="<?php echo $row['id_question'] ?>" type="radio" value="<?php echo $row['answer2'] ?>"><?php echo $row['answer2'] ?>
<br>
<input name="<?php echo $row['id_question'] ?>" type="radio" value="<?php echo $row['answer3'] ?>"><?php echo $row['answer3'] ?>
<br>
<input name="<?php echo $row['id_question'] ?>" type="radio" value="<?php echo $row['answer4'] ?>"><?php echo $row['answer4'] ?>
<?php }
}
else {
echo "0 results";
}
$conn->close();
?>
<button type="submit">Submit feedback</button>
</form>