GET With A Form

If you're using PHP, the chances are that you want to be able to have information persist between pages. A form is a simple way to get input from a user. The GET method is one way of passing that data from one page to another. Like before, we can use IF statements and a single script to achieve this effect.

<title>PHP Test</title>
if (isset($_GET['name']))
   $thename= $_GET['name'];
   echo "<h1>Hello ".$thename."</h1>";
   echo "<form action='get.php' method='GET'>
   <p>Enter your name: <input type='text' name='name' size='50'><br>
   <input type='reset' value='Clear'>&nbsp;<input type='submit' value='Submit'>

In this script, a form is displayed. When the method attribute of a form is set to 'GET', the data for the form is passed through the URL.

You can pass data this way, but what if there's a ton of it?

Add another text box to the form (the input tag). Have the user type in their age too. Adapt the IF clause so that the script displays the person's age. Look at what happens to the URL when more than one variable is passed.