Specifications
Accessing Form Variables
The whole point of using the order form is to collect the customer order. Getting the details of
what the customer typed in is very easy in PHP.
Within your PHP script, you can access each of the form fields as a variable with the same
name as the form field. Let’s look at an example.
Start by adding the following lines to the bottom of your PHP script:
echo “<p>Your order is as follows:”;
echo “<br>”;
echo $tireqty.” tires<br>”;
echo $oilqty.” bottles of oil<br>”;
echo $sparkqty.” spark plugs<br>”;
If you refresh your browser window, the script output should resemble what is shown in Figure
1.4. The actual values shown will, of course, depend on what you typed into the form.
PHP Crash Course
C
HAPTER 1
1
PHP CRASH
COURSE
19
FIGURE 1.4
The form variables typed in by the user are easily accessible in processorder.php.
A couple of interesting things to note in this example are discussed in the following subsec-
tions.
Form Variables
The data from the script will end up in PHP variables. You can recognize variable names in
PHP because they all start with a dollar sign (
$). (Forgetting the dollar sign is a common pro-
gramming error.)
03 7842 CH01 3/6/01 3:39 PM Page 19