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

<form id="form1" name="form1" method="post" action="">
        <select name="age" id="age">
        <option value="0">Select Age</option>
  echo '<option value="1">'.$i.'</option>';

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

If you are currently echoing every age option under 100, do you want the selected age?

Have you tried the get method?

$_Get Variable on w3s:


Session Variables:

Jump to Post

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['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, learning, and sharing knowledge.