I'm working on this quiz. Something has gone wrong with my form though. The page displays a random question but instead of showing 4 different answer options, it repeats one option 4 times. How do should I go about fixing this?
<?php
SESSION_START();
//Connect to MySQL:
$con = new mysqli("localhost", "root", "", "quizproject");
?>
<html>
<body>
<h1>Hello, <?php echo $_SESSION["fname"]; " " ?> <?php echo $_SESSION["lname"]; ?>.</h1>
<p><h2>Quiz Time! Please answer each of the following questions:</h2><br>
<?php
//retrieve question list:
$get_questions = $con->prepare("SELECT question_ID, question FROM questions");
$get_questions->execute();
$get_questions->bind_result($question_ID, $question);
$questions = array();
while ($get_questions->fetch()) {
$questions[$question_ID] = array($question_ID, $question, array());
}
// retrieve answer list:
$get_answers = $con->prepare("SELECT id, question_ID, answers, correct FROM answers");
$get_answers->execute();
$get_answers->bind_result($id, $question_ID, $answers, $correct);
while ($get_answers->fetch()) {
$questions[$question_ID][2][$id] = array($id, $answers, $correct);
}
// Scramble the array and print:
shuffle($questions);
?>
<form method="get" action="result.php">
<div class="question">
<label><h2><?php echo $question ?></h2></label>
<br>
<input type="hidden" name="question<?php echo $question_ID ?>_id" value="<?php echo $question_ID; ?>" id="question<?php echo $question_ID; ?>_id"/>
<input name="answer<?php echo $id ?>" id="q<?php echo $id ?>_a1" value="1" type="radio"/>
<label for="q<?php echo $id ?>_a1"> <?php echo $answers ?></label><br>
<input name="answer<?php echo $id?>" id="q<?php echo $id ?>_a2" value="2" type="radio"/>
<label for="q<?php echo $id ?>_a2"> <?php echo $answers ?></label><br>
<input name="answer<?php echo $answers ?>" id="q<?php echo $id ?>_a3" value="3" type="radio"/>
<label for="q<?php echo $id ?>_a3"> <?php echo $answers ?></label><br>
<input name="answer<?php echo $id ?>" id="q<?php echo $id ?>_a4" value="4" type="radio"/>
<label for="q<?php echo $id ?>_a4"> <?php echo $answers ?></label><br>
</div>
<?php
echo "<br><input name=\"submit\" type=\"submit\" value=\"Submit\">";
echo "</form></body></html>";
?>
</form>
</html>
</body>