Creating The PHP Form Processor
This tutorial is to help out those following the book PHP and mySQL in
web development.
1.
Open a new Notepad document. Click file=>save and save this as an html doc
on your desktop, with all files showing in the save as type. Save this with
the name orderprocessing.php
2. PHP documents follow HTML tags as well as PHP tags. The basic layout
of this form will be done in HTML.
The next step is to define the html, head and body of the html. The head
is where the title goes and the body is where the contents of the page goes
that you see. The head ends prior to the start of the body. You should add
these to your document so it looks like this:
<HTML>
<HEAD><TITLE>Bob's Auto Parts - Order
Results</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>
4.
The next step is to realize what you need to recreate this form. Once we
decide what we need, we will have to design our page in a way that html can
support the layout.
The order that is processed will have the same Header as your form, Bob's
Auto Parts, But the name in the H@ tag is slightly different. It should be
Order Results.
<HTML>
<HEAD><TITLE>Bob's Auto Parts - Order Results</TITLE>
</HEAD>
<BODY>
<H1>Bob's Auto Parts</H1>
<H2>Order Results</H2>
</BODY>
</HTML>
5. Under the Order results we would like PHP to show us the Order
Processed. The PHP server will process any command in PHP language. We can
place a command between a <? and ?>. What is after the work "echo" will be
output to your HTML, therefore it can be written in HTML
Type this in:
<HTML>
<HEAD><TITLE>Bob's Auto Parts - Order Results</TITLE>
</HEAD>
<BODY>
<H1>Bob's Auto Parts</H1>
<H2>Order Results</H2>
<?
echo "<P>Order Processed.";
?>
</BODY>
</HTML>
6. We can add comment code with the format below. PHP will not interpret
what's in a comment tag, however it helps to add them when getting into
longer pages where you need note each part.
/*this is a comment
*/
7. The echo tag above shows static content in that we posted the text in
the tag to be displayed. It can also be used for dynamic content. The
time and date. The word date is a functions and the contents of the
parentheses are augments to specify the function.
- H=hour in 24 hour time,
- i= minutes,
- j=day of the month,
- S= ordinal suffix,
- F=year
<?
echo "<P>Order Processed.";
echo date("H:i, jS F")
echo "<br>";
?>
8. We can use PHP to pass variables to the form and display them. In our
form, we created the variables tireqty, oilqty, sparkplugqty. The $ will
tell PHP this is a variable.
<?
echo "<P>Order Processed.";
echo date("H:i, jS F");
echo "<br>";
echo $tireqty." tires<BR>";
echo $oilqty." bottles of oil<BR>";
echo $sparkplugqty." spark plugs<BR>";
?>
9. The resulting PHP doc will look like this:
<HTML>
<HEAD><TITLE>Bob's Auto Parts - Order Results</TITLE>
</HEAD>
<BODY>
<H1>Bob's Auto Parts</H1>
<H2>Order Results</H2>
<?
echo "<P>Order Processed.";
echo date("H:i, jS F");
echo "<br>";
echo $tireqty." tires<BR>";
echo $oilqty." bottles of oil<BR>";
echo $sparkplugqty." spark plugs<BR>";
?>
</BODY>
</HTML>
|