After page3.php i go back to page1.php but i cant assign a new value to $_SESSION['answer'] anymore. i'm getting the error Undefined Index: answer
PAGE 1:
<?php
session_start();
$true_status = 'unchecked';
$false_status = 'unchecked';
if (isset($_POST['Submit1'])) {
$_SESSION['answer'] = $_POST['answer'];
$selected_radio = $_POST['answer'];
if ($selected_radio == 'true') {
$true_status = 'checked';
}
else if ($selected_radio == 'false') {
$false_status = 'checked';
}
}
?>
<body>
<FORM name ="form1" method ="post" action = 'page2.php'>
<h2>Q1. True or False?</h2>
<Input type = 'Radio' Name ='answer' value= 'true'
<?php echo $true_status; ?>
>TRUE
<Input type = 'Radio' Name ='answer' value= 'false'
<?php echo $false_status; ?>
>FALSE
<p>
<Input type = "Submit" Name = "Submit1" VALUE = "Next Page">
</FORM>
</body>
I'm just trying to display the value of $_SESSION['answer']
PAGE 2:
<?php
session_start();
echo $_SESSION['answer'];
?>
<body>
<FORM name ="form3" method ="post" action ="page3.php">
<Input type = "Submit" name="Submit2" value="Next Page" >
</FORM>
</body>
PAGE 3:
<?php
session_start();
echo $_SESSION['answer'];
$_SESSION = array();
session_destroy();
?>
<body>
<FORM name ="form2" method ="post" action ="page1.php">
<Input type = "Submit" name="Submit3" value="TRY QUIZ AGAIN" >
</FORM>
</body>