我在同一页面上生成了一个带有问题的测验。我想将答案保存到数据库中以查看答案。我该怎么办?以下是我如何生成测验的代码。如何存储所选答案并进行检查?
<?php for($i=1;$i<=3;$i++)//loop for extracting question and options
{?>
<form action = "CHECK.php" method="POST">
<?PHP
$sql = "SELECT QUESTION FROM T_QUESTIONS WHERE QUES_NO=$i LIMIT 1";
if($result = mysqli_query($conn, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>QUESTION $i :</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['QUESTION'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
}
?>
<?PHP
$s = "select OPTION1,OPTION2,OPTION3,OPTION4,OPTION5,CORRECT_ANSWER from T_QUESTIONS where QUES_NO='$i'";
$result=mysqli_query($conn,$s);
if(!mysqli_query($conn,$s))
echo mysqli_error($conn);
else
while ($row = $result->fetch_assoc()) {
?>
<input type="radio" name="choice<?php echo $i; ?>" value="<?php echo $row['OPTION1']; ?>" /> A. <?php echo $row['OPTION1']."<br>"; ?>
<input type="radio" name="choice<?php echo $i; ?>" value="<?php echo $row['OPTION2']; ?>" /> B. <?php echo $row['OPTION2']."<br>"; ?>
<input type="radio" name="choice<?php echo $i; ?>" value="<?php echo $row['OPTION3']; ?>" /> C. <?php echo $row['OPTION3']."<br>"; ?>
<input type="radio" name="choice<?php echo $i; ?>" value="<?php echo $row['OPTION4']; ?>" /> D. <?php echo $row['OPTION4']."<br>"; ?>
<input type="radio" name="choice<?php echo $i; ?>" value="<?php echo $row['OPTION5']; ?>" /> E. <?php echo $row['OPTION5']."<br>"; ?>
<br>
<?php
}
}
?>
</form>
<button style ="color:red;border radius:10px;margin:100px;height:100px;width:200px;font-size:30px"> <a href=CHECK.php>SUBMIT TEST</a></button>
Correct_OPTION与问题和选项位于同一表中。