I am creating several forms all submitted via POST in PHP and stored in sessions. However I cannot get the radio button to store a value into the session. I am trying to store the radio button’s value in the session but cannot get it display. Any help would be greatly appreciated.
Below is a sample of the code I am using;
HTML:
<form method="POST" action="testform2.php">
<input type="radio" id="age" name="age" value="yes"/>Yes<br/>
<input type="radio" id="age" name="age" value="no"/>No<br/>
If no, please tell us your date of birth:<br/>
<textarea id="age" name="age" rows="5" cols="40"></textarea><br/><br/>
<input type="submit" value="Next"></br>
</form>
PHP: At the start of the next form (testform2.php)
<?php
session_start();
$age=$_POST['age'];
$_SESSION['age']=$age;
echo $_SESSION['age'];
?>
With this I don’t get anything from the echo despite clicking on the radio button.
Ensure firstly you have started the session on both pages, and any other pages you use as the first line in the page (well after
You can debug by doing
this will print everything in POST, then do the same for session. If its not in the post print then there is an issue with your form, if its in the post print but not in the session print then something is going wrong with it being set.