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:

<form action="#" method="post"> student: <input type="text" name="student" value="" /><br /> status: <select name="status"> <option value="full">Full Time</option> <option value="part">Part Time</option> <option value="audit">Audit Only</option> </select><br /> <input type="submit" /> </form>

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:

<?php echo "student = ".$_POST['student']."<br />"; echo "status = ".$_POST['status']; ?>

Place values in the form above, click the submit button and produce:

student =
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.

Includes   < <  PREVIOUS   Table of Contents NEXT  > >   Pick Lists

Developed with HTML-Kit
Sandersongs Web Tutorials
Contact the Webmasterwith comments.
©2021, by Bill Sanders, all rights reserved.
This domain had 4,141 different visits in the last 30 days.
This page was last modified on our server on 4 Jun 2008
and last refreshed on our server at 4:14 pm, MST
This file took 0.00871 seconds to process.