/beyond/php/article.php/3472451/PHP-Tutorial-Processing-the-Form.htm PHP Tutorial: Processing the Form

PHP Tutorial: Processing the Form

By Vince Barnes

Our order form sent its data to a file called processorder.php via the instruction:

ACTION="processorder.php" method=post


This is the content of that file:


<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Acme Widget Company</title>
<body style="font-family: Arial">
Acme Widget Company</h1>

$qtybases = $_POST['qtybases'];
$qtystems = $_POST['qtystems'];
$qtytops = $_POST['qtytops'];

<p>Thank you!</p>
<p>Your order for:</p>

echo $qtybases.' bases<br>';
echo $qtystems.' stems<br>';
echo $qtytops.' tops<br>';

<p>was processed.</p>

(File Content ends above this line)


In here there's plenty of interesting PHP code to take a look at!  We'll start with that first piece of PHP code:

$qtybases = $_POST['qtybases'];
$qtystems = $_POST['qtystems'];
$qtytops = $_POST['qtytops'];

(To make life easier, I've left off the opening and closing tags when looking at the code itself & I'll continue like that throughout this series.)


Each of these statements is an "assignment" instruction.  The equal sign in the middle designates it as such and tells PHP to "make the value of this Equal to the value of that."  In this case we're making the value of one variable equal to the value of another variable (a "variable" is a data element whose value can change, as opposed to a "constant" which is a data element whose value can not change.)


The variables on the left, $qtybases for example, are variable fields that are being dynamically defined by these statements.  This means that no other statement was needed to create the variable $qtybases; it's being defined right here.  Those variables are being set to the values of some "POST" variables.  "POST" variables are those that are passed down from the preceding form by means of the POST method (remember the statement <FORM ACTION="processorder.php" method=post> in the form.)  We'll get into more detail about these variables later; for now suffice it to say that this format, using the names that were used in the calling form, will pick up the variables being passed down.


Then there's that group of echo statements.  "Echo" works like a "print here" command.  Remember that the PHP processor is going to interpret the PHP code in this page and then send the page down to the client browser.  Whatever the echo prints out becomes part of the resulting page.  Each of these echo statements prints out the value of a variable and a text string enclosed in quotes.  Look closely and you'll see a period between the two  This tells PHP to concatenate the two strings (the value of the variable and the quoted string) together.  Thus, if $qtybases has a value of 5 then the first echo statement will return this:

5 bases<br>

which, on the resulting web page, will show up as "5 bases" followed by a line break.


Try  it out on our example.

Continue to the next part of this Tutorial

Return to the Tutorial Series Index

  • Web Development Newsletter Signup

    Invalid email
    You have successfuly registered to our newsletter.
Thanks for your registration, follow us on our social networks to keep up-to-date