将变量从第一页传递到第三页PHP

I have a drop down list on page one with select code:

print "Select week for season 1:  <select name='Week_select'> <br>";

On page 2 I have

$varWeek=$_POST['Week_select'];

Then another drop down list:

print "Select a team that played season 1and week $varWeek:  <select name='Team_select'><br>";

So far so good and many thanks to all who have gotten me this far.

Now when I go to page 3, I lose $varWeek

I see that I should either use a $_GET or pass it as hidden. I tried $varWeek=$_GET['Week_select']; but that didn't work.

I am unsure how to pass it hidden. Please help me understand a little more. Many thanks in advance

A better approach would be to register those variables as session variables. This way they won't show up in the URL and you will be able to access them across several pages. Have a read here:

http://www.php.net/manual/en/intro.session.php

You can access/store a session variable like this:

$_SESSION['varname'] = 'value';

and on another page

var_dump($_SESSION['varname']);

Add the variable into the form, like you said, as a hidden field, like so:

print '<input type="hidden" name="Week_select" value="'. $_GET['Week_select'] .'" />';

Then on the page which handles the form, the variable will be available in $_POST['Week_select']