I'm a beginner programmer and I'm busy setting up a PHP online quizzer site and I'm running into a bit of a problem with my choice selection.
I need my radio button to stay selected when going to the next page.
Here's my code for the page:
Each time I click next and go back to the previous page my selection is erased. How do I keep it saved?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf=8">
<title>PHP Quizzer</title>
</head>
<body>
<header>
<div class = "container">
<h1>PHP Quizzer</h1>
</div>
</header>
<main>
<div class="container">
<div class="current"> Question <?php echo $question['question_number']; ?> of <?php echo $total; ?> </div>
<p class="question">
<?php echo $question['text']; ?>
</p>
<form method="post" action="process.php">
<ul class="choices">
</select>
<?php while($row =$choices-> fetch_assoc()) : ?>
<li><input name="choice" type="radio" value="<?php echo $row['id']; ?>" /><?php echo $row['text'] ; ?></li>
<?php endwhile; ?>
</ul>
<input type="submit" value="Submit" />
<input type="hidden" value="<?php echo $number;?>" name="number"/>
<!--<a href="questions.php?n=1" class = "previous">Previous</a>-->
<!--<a href="questions.php?n=" name = "next">Next</a>-->
<?php
$next_button='';
$previous_button='';
$enabled='TRUE';
if ($number<$total)
{
$number++;
$next_button="<a href='questions.php?n=$number name='next'>Next</a>";
echo($next_button);
}
if ($number>2)
{
$number--;
echo "<a href='questions.php?n=" . ($number-1) . "' class='button'>Previous</a></li>";
#$previous_button="<a href='questions.php?n= name='previous'>Previous</a>";
echo($previous_button);
}
?>
</form>
</div>
</main>
</header>
</body>
</html>
<?php
#if(count($id_list) < $num) {die("I need more questions in the database.");}
?>
Here's what I got in where my radio buttons are:
<?php while($row =$choices-> fetch_assoc()) : ?>
<li><input name="choice" type="radio" value="<?php echo $row['id']; ?>" /><?php echo $row['text'] ; ?></li>
<?php endwhile; ?>
</ul>
<input type="submit" value="Submit" />
<input type="hidden" value="<?php echo $number;?>" name="number"/>
I need my selection to save each time I go to the next page.