How To Store A Radio Button In A Session For Use On Another Page?
So I need to store the choice of selected radio button in session and then based on that value perform an action on a different page. Page1.php: ];
$_SESSION['person'] = $person;
You will have to have the inputs be wrapped inside of a form:
<form method="post" action="Page2.php">
<input type="radio" name="person" value="p1"/>Person1
<input type="radio" name="person" value="p2"/>Person2
<input type="submit" value="submit"/>
</form>
Now you will be able to use that $_SESSION variable on mostly any page, if the session is not destroyed or overwritten.
To retrieve a session value on another page, simply use:
<?php
session_start();
$person = $_SESSION['person'];
?>
Solution 2:
You can do this by posting the data in your form through to your Page2.php page you don't need a session.
$_POST["person"];
Will pull the data out so that you can do:
string person = $_POST["person"]
if(person == something){
//do something
}
else{
//do something else
}
You only need a session if you intend to use the variable value that is returned on multiple occasions. If that's the case then you can find a good easy tutorial here:
http://www.w3schools.com/php/php_sessions.asp
The basics would look something like this within your Page2.php:
session_start();
$_SESSION["person"] = $_POST["person"];
Hope that helps!
Post a Comment for "How To Store A Radio Button In A Session For Use On Another Page?"