In the HTML tutorial, we discovered variables are passed from one web page to another through submitting a form. See also the discussion on Sessions in this tutorial. Essentially, each form element (checkbox, textarea, password box, etc) is given a name. When a value is given to that name by the viewer, and the form is submitted, the name/value pair is passed to the handler page.
So, if we have:
it looks like so:
From the code in the first box above, we see that the text box has a name of 'student'. Whatever the viewer types into the text box becomes the value of that box. If the viewer types in 'Smith', then the text box has a name of 'student', a value of 'Smith', thus the name/value pair for the text box becomes 'student/Smith'.
Similarly, the drop-down select box has a name of 'status'. The value of whichever option the viewer chooses becomes the value of the select box. If the viewer chooses 'Full Time', the select box has a name of 'status' and a value of 'full', thus a name/value pair of 'status/full'.
We also see in the code above the action attribute of the form tag is set to '#'. Now, when the viewer clicks on the Submit Query button, these name/value pairs are sent to '#' (which means they are sent back to the current page for processing). Because the method attribute of the form tag was set to post, PHP stores all the name/value pairs in an array on the handler page called $_POST. We can call the variables that were passed as follows:
Place values in the form above, click the submit button and produce:
status =
If the method attribute of the form tag was 'get', you use $_GET array instead. If some variables are passed by 'post' and some by 'get', use the $_REQUEST array, which will capture both.