Forms - or doing something a little more useful with PHP
You have seen so far a lot about the structure of PHP but with the use of forms, PHP can allow you to process
your users requirements what ever they might be.
Below is a standard form which in the
action attribute of the form tag has the name of
the file that the form currently resides in.
<form action="login.php" method="post">
<label for="username">Username</label> <input type="text" name="username" />
<label for="password">Password</label> <input type="password" name="password" />
<br/><input type="submit" value="Login"/>
</form>
At the top of the file login.php should go the following:
<?php
if (!empty($_POST))
{
//if the code reaches here it means the form has been posted!
echo $_POST["username"];
echo $_POST["password"];
}
?>
Notice that PHP code needs to go within PHP tags.
This above code snippet extracts the form values from the post array.
The following line of code:
if (!empty($_POST))
Ensures that there are some post values otherwise it doens't try to read the post array.
This is the post array
$_POST which contains the form values and this is the name
one of the form element that was posted in the above form
password.
Comments to date: 5. Page 1 of 1. Average Rating:

Zaiyah 2:40am on Friday, July 15th, 2011 
Got it! Thanks a lot again for hleipng me out!
dev 4:28am on Thursday, June 30th, 2011 
post some useful programs worst tutorial site i ever seen
Deepak 9:07am on Wednesday, May 25th, 2011 
Deepak 9:06am on Wednesday, May 25th, 2011 
Priettifurn 7:08pm on Friday, April 1st, 2011
Written by Dominic Skinner
Last Updated: 2011-10-25 16:00:38