Now that you've got the basics of PHP variables and operators down, the second article in this series takes a look at PHP's form-processing capabilities, and introduces you to the comparison and logical operators and the "if-else" and "switch" family of conditional statements.
Now for the other half of the puzzle - the "login.php4" script. Normally, this script would accept the name entered, check whether the user existed, and either grant or deny access to the site. Since we have yet to cover PHP's conditional statements and logical operators, we're not going to demonstrate that just yet - instead, we're simply going to show you how the data submitted in the first form is injected into "login.php4" and can be used in that file.
Here's "login.php4"
<html>
<head>
<basefont face="Arial">
</head>
<body>
<center>
<font face="Arial" size="-1">
I wonder if you've heard of Shakespeare, <? echo $name; ?>.
<p>
He postulated that a rose by any other name would smell just as sweet.
<p>
What do you think?
</font>
</center>
</body>
</html>
And when you enter some data into the form [say "bill"] and
submit it, here's what you should see:
I wonder if you've heard of Shakespeare, bill.
He postulated that a rose by any other name would smell just as sweet.
What do you think?
As you can see, whenever a form is submitted to a PHP script,
all variable-value pairs within that form automatically become available for use within the script. In the example above, once the form is submitted, the variable $name is automatically created in the PHP script "login.php4", and is populated with the value entered into the form by the user.
If you were to try doing the same thing in Perl, you'd need to explicitly write code to extract and obtain the values of the variables in the form. By automatically creating and populating the variables for you, PHP simplifies your code and speeds up development time - two reasons why PHP is preferred to Perl when it comes to form processing.
Obviously, PHP also supports the POST method of form submission. All you need to change the METHOD attribute to "POST".