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!

Recommended Answers

All 3 Replies

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'];

Thanks for reply's!
Got it to work!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.