Ok we are going to make a simple form that will display the information on the next page using the variables we have learnt about and the echo function.
first you need to make a document called index.htm, this is where the form will go, here is the code for the form:
HTML Code:
<html> <form method="post" action="index.php"> <p>Name:
<input name="name" type="text"> </p> <p>Email:
<label> <input name="email" type="text"> </label> </p> <p> <label>Comment:<br> <textarea name="comment" cols="50" rows="6"></textarea> </label> </p> <p> <label> <input type="submit" name="Submit" value="Submit"> </label> </p> </form> </html> I made this in dreamweaver to be quick but you can still do the same in any other text program.
You will notice that i have given everything a relevant name, this is important and you will notice why in the php code. Also you will see i have give the form an action, this action needs to be the file name of the .php file we are about to create, for this i have called it index.php
The php code:
PHP Code:
<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$comment = $_REQUEST['comment'];
echo "Hello $name, Your email is $email <br /><br />Your comment was:<br />$comment";
?>
Ok we know how the echo works and you will now see that when you use double quotes not only can you display the value of a variable but you can also use html inside it!
How the code works?
PHP Code:
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$comment = $_REQUEST['comment'];
Here we have set the variables i will use the name variable as an example, i hope that you have noticed that the variable name has a request for the name box, the reason you have to request is to get the value of what has just been posted so the format is... $var_name = $_REQUEST['content']; ... content being the name of the textbox, options, combo boxes etc...
so now you know how to get the information into a variable all you have to do is print it on the page using the echo function:
PHP Code:
echo "Hello $name, Your email is $email <br /><br />Your comment was:<br />$comment";
You Should already know the echo function with variables from past tutorials so i am just mentioning it briefly, simply use double quotes so you can print variables and include some new breaks in the content to shove the comment down a couple of lines to make it look better.
Hope this has helped you, feel free to ask any questions.