0

Hello,
Anyone know how to get a session var. from a while loop.
Here is some code:

<form id="form1" name="form1" method="post" action="">
      <p>Age:
        <select name="age" id="age">
        <option value="0">Select Age</option>
        <?php
$i=1;
while($i<=100)
  {
  echo '<option value="1">'.$i.'</option>';
  $i++;
  }
?>

It's from a drop down menu.
Here is the code for the session var I want to create:

if ($_POST && !empty($_POST['age'])) {
		echo $_SESSION['age'] = $_POST['age'];
		}

Any help would be great!

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by phpDave
1

Why not just echo out $_POST as that is all you are trying to do anyway. Otherwise, if you want to store the age in a session, you need to allocate your posted age to a session variable and to do that you need to do:

session_start();
$_SESSION['age'] = $_POST['age'];
echo $_SESION['age'];
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.