Pages

Friday, October 29, 2010

Variables in a Form

First you make a regular HTML form page, like we learnt here:
<form action="form.php" method="post">
Your name: <input type="text" name="name"><br>
Your age: <input type="text" name="age"><br>

<input type="submit">
</form>
This form consists of two text boxes, one which is called "name" and another which is called "age". These names are our variables. We save this file as "form.html", but notice on the first line how the form points to a file called "form.php"? Well, that is a seperate file, consisting of this PHP code:
Hi <?php print $name; ?>.
You are <?php print $age; ?> years old.
The form will pass the variables on to the PHP page, where they will be displayed as the text the user entered. Try it out:

Your name: 
Your age:
 

0 Comments:

Post a Comment