eg-259:lecture18
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
eg-259:lecture18 [2009/11/24 14:50] – eechris | eg-259:lecture18 [2013/03/08 18:04] (current) – [PHP for Web Applications] eechris | ||
---|---|---|---|
Line 2: | Line 2: | ||
====== PHP for Web Applications ====== | ====== PHP for Web Applications ====== | ||
- | **Lecture 18**: To be given on Monday 30th November, 2009. | + | **Supplementary Material** |
+ | |||
+ | Provided for Reference. This material is no longer taught | ||
**Lecturer**: | **Lecturer**: | ||
Using PHP for web applications development. | Using PHP for web applications development. | ||
- | |||
Line 227: | Line 228: | ||
* If the query string has '' | * If the query string has '' | ||
- | * '' | + | * '' |
* Query matching will also turn check box group '' | * Query matching will also turn check box group '' | ||
Line 243: | Line 244: | ||
* //The Form Page (just HTML)// : [[/ | * //The Form Page (just HTML)// : [[/ | ||
- | {{eg-259:l18-popcorn3.html.png|The Form Page }} | + | < |
+ | <form action = " | ||
+ | method = " | ||
+ | <h2> Welcome to Millennium Gymnastics Booster Club Popcorn | ||
+ | Sales </ | ||
+ | < | ||
+ | <!-- Text widgets for the customer' | ||
+ | < | ||
+ | <td> Buyer' | ||
+ | < | ||
+ | <input type = " | ||
+ | size = " | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | <td> Street Address: </ | ||
+ | < | ||
+ | <input type = " | ||
+ | size = " | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | <td> City, State, Zip: </ | ||
+ | < | ||
+ | <input type = " | ||
+ | size = " | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | <p /> | ||
+ | <table border = " | ||
+ | <!-- First, the column headings --> | ||
+ | < | ||
+ | <th> Product </ | ||
+ | <th> Price </ | ||
+ | <th> Quantity </ | ||
+ | </ | ||
+ | <!-- Now, the table data entries --> | ||
+ | < | ||
+ | <td> Unpopped Popcorn (1 lb.) </ | ||
+ | <td> $3.00 </ | ||
+ | <td align = " | ||
+ | <input type = " | ||
+ | size = " | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | <td> Caramel Popcorn (2 lb. canister) </ | ||
+ | <td> $3.50 </ | ||
+ | <td align = " | ||
+ | <input type = " | ||
+ | size = " | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | <td> Caramel Nut Popcorn (2 lb. canister) </ | ||
+ | <td> $4.50 </ | ||
+ | <td align = " | ||
+ | <input type = " | ||
+ | size = " | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | <td> Toffey Nut Popcorn (2 lb. canister) </ | ||
+ | <td> $5.00 </ | ||
+ | <td align = " | ||
+ | <input type = " | ||
+ | size = " | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | <p /> | ||
+ | < | ||
+ | <h3> Payment Method </ | ||
+ | <p> | ||
+ | <input type = " | ||
+ | checked = " | ||
+ | Visa | ||
+ | <br /> | ||
+ | <input type = " | ||
+ | Master Card | ||
+ | <br /> | ||
+ | <input type = " | ||
+ | value = " | ||
+ | Discover | ||
+ | <br /> | ||
+ | <input type = " | ||
+ | Check | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <!-- The submit and reset buttons --> | ||
+ | <input type = " | ||
+ | <input type = " | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
---- | ---- | ||
<code html> | <code html> | ||
- | <?xml version = " | + | < |
- | < | + | |
- | " | + | |
- | + | ||
<!-- popcorn3.html - This describes the popcorn sales form --> | <!-- popcorn3.html - This describes the popcorn sales form --> | ||
- | < | + | < |
< | < | ||
+ | <meta charset=" | ||
< | < | ||
</ | </ | ||
< | < | ||
- | + | | |
- | | + | method = " |
- | method = " | + | |
<h2> Welcome to Millennium Gymnastics Booster Club Popcorn | <h2> Welcome to Millennium Gymnastics Booster Club Popcorn | ||
- | Sales </h2> | + | |
< | < | ||
- | + | | |
- | <!-- Text widgets for the customer' | + | |
<tr> | <tr> | ||
<td> Buyer' | <td> Buyer' | ||
- | <td> <input type = " | + | <td> |
- | size = " | + | |
+ | size = "30" required placeholder=" | ||
+ | | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> Street Address: </td> | <td> Street Address: </td> | ||
- | <td> <input type = " | + | <td> |
- | size = " | + | |
+ | size = "30" required placeholder = " | ||
+ | | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td> City, State, Zip: </td> | <td> City, State, Zip: </td> | ||
- | <td> <input type = " | + | <td> |
- | size = " | + | |
+ | size = "30" required placeholder=" | ||
+ | | ||
</tr> | </tr> | ||
</ | </ | ||
<p /> | <p /> | ||
<table border = " | <table border = " | ||
- | + | | |
- | <!-- First, the column headings --> | + | |
<tr> | <tr> | ||
<th> Product </th> | <th> Product </th> | ||
Line 294: | Line 388: | ||
<th> Quantity </th> | <th> Quantity </th> | ||
</tr> | </tr> | ||
- | + | | |
- | <!-- Now, the table data entries --> | + | |
<tr> | <tr> | ||
<td> Unpopped Popcorn (1 lb.) </td> | <td> Unpopped Popcorn (1 lb.) </td> | ||
<td> $3.00 </td> | <td> $3.00 </td> | ||
<td align = " | <td align = " | ||
- | | + | |
- | | + | size = "3" min=" |
+ | | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
Line 308: | Line 401: | ||
<td> $3.50 </td> | <td> $3.50 </td> | ||
<td align = " | <td align = " | ||
- | | + | |
- | | + | size = "3" min=" |
+ | | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
Line 315: | Line 409: | ||
<td> $4.50 </td> | <td> $4.50 </td> | ||
<td align = " | <td align = " | ||
- | | + | |
- | | + | size = "3" min=" |
+ | | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
Line 322: | Line 417: | ||
<td> $5.00 </td> | <td> $5.00 </td> | ||
<td align = " | <td align = " | ||
- | | + | |
- | | + | size = "3" min=" |
+ | | ||
</tr> | </tr> | ||
</ | </ | ||
<p /> | <p /> | ||
- | + | | |
- | <!-- The radio buttons for the payment method --> | + | |
<h3> Payment Method </h3> | <h3> Payment Method </h3> | ||
<p> | <p> | ||
<input type = " | <input type = " | ||
- | | + | |
- | Visa <br /> | + | Visa |
+ | | ||
<input type = " | <input type = " | ||
- | | + | |
+ | | ||
<input type = " | <input type = " | ||
- | value = " | + | |
- | Discover <br /> | + | Discover |
+ | | ||
<input type = " | <input type = " | ||
- | | + | |
- | + | | |
- | <!-- The submit and reset buttons --> | + | |
+ | <!-- The submit and reset buttons --> | ||
<input type = " | <input type = " | ||
<input type = " | <input type = " | ||
Line 362: | Line 459: | ||
---- | ---- | ||
<code php> | <code php> | ||
- | <?php echo("<? | + | < |
- | < | + | |
- | " | + | |
<!-- popcorn3.php - Processes the form described in | <!-- popcorn3.php - Processes the form described in | ||
- | popcorn3.html | + | popcorn3.html |
- | | + | --> |
- | < | + | <html lang=" |
< | < | ||
+ | <meta charset=" | ||
< | < | ||
</ | </ | ||
< | < | ||
<?php | <?php | ||
- | |||
// Get form data values | // Get form data values | ||
- | + | $unpop=$_POST[" | |
- | | + | $caramel=$_POST[" |
- | $caramel = $_POST[" | + | $caramelnut=$_POST[" |
- | $caramelnut = $_POST[" | + | $toffeynut=$_POST[" |
- | $toffeynut = $_POST[" | + | $name=$_POST[" |
- | $name = $_POST[" | + | $street=$_POST[" |
- | $street = $_POST[" | + | $city=$_POST[" |
- | $city = $_POST[" | + | $payment=$_POST[" |
- | $payment = $_POST[" | + | |
// If any of the quantities are blank, set them to zero | // If any of the quantities are blank, set them to zero | ||
- | + | if($unpop=="" | |
- | | + | $unpop=0; |
- | if ($caramel == "" | + | if($caramel=="" |
- | if ($caramelnut == "" | + | $caramel=0; |
- | if ($toffeynut == "" | + | if($caramelnut=="" |
+ | $caramelnut=0; | ||
+ | if($toffeynut=="" | ||
+ | $toffeynut=0; | ||
// Compute the item costs and total cost | // Compute the item costs and total cost | ||
- | + | $unpop_cost=3.0*$unpop; | |
- | | + | $caramel_cost=3.5*$caramel; |
- | $caramel_cost = 3.5 * $caramel; | + | $caramelnut_cost=4.5*$caramelnut; |
- | $caramelnut_cost = 4.5 * $caramelnut; | + | $toffeynut_cost=5.0*$toffeynut; |
- | $toffeynut_cost = 5.0 * $toffeynut; | + | $total_price=$unpop_cost+$caramel_cost+$caramelnut_cost+$toffeynut_cost; |
- | $total_price = $unpop_cost + $caramel_cost + | + | $total_items=$unpop+$caramel+$caramelnut+$toffeynut; |
- | $caramelnut_cost + $toffeynut_cost; | + | |
- | $total_items = $unpop + $caramel + $caramelnut + $toffeynut; | + | |
// Return the results to the browser in a table | // Return the results to the browser in a table | ||
- | |||
?> | ?> | ||
<h4> Customer: </h4> | <h4> Customer: </h4> | ||
<?php | <?php | ||
- | | + | print(" |
?> | ?> | ||
- | <p /> <p /> | + | <p /> |
- | <table border = " | + | |
- | < | + | <table border = " |
+ | < | ||
+ | | ||
+ | | ||
<tr> | <tr> | ||
<th> Product </th> | <th> Product </th> | ||
Line 423: | Line 516: | ||
<td> Unpopped Popcorn </td> | <td> Unpopped Popcorn </td> | ||
<td> $3.00 </td> | <td> $3.00 </td> | ||
- | <td> <?php print (" | + | < |
- | <td> <?php printf ("$ %4.2f", | + | < |
- | | + | |
</tr> | </tr> | ||
<tr align = " | <tr align = " | ||
<td> Caramel Popcorn </td> | <td> Caramel Popcorn </td> | ||
<td> $3.50 </td> | <td> $3.50 </td> | ||
- | <td> <?php print (" | + | < |
- | <td> <?php printf ("$ %4.2f", | + | < |
- | | + | </tr> |
- | </tr> | + | |
<tr align = " | <tr align = " | ||
<td> Caramel Nut Popcorn </td> | <td> Caramel Nut Popcorn </td> | ||
<td> $4.50 </td> | <td> $4.50 </td> | ||
- | <td> <?php print (" | + | < |
- | <td> <?php printf ("$ %4.2f", | + | < |
- | | + | |
</tr> | </tr> | ||
<tr align = " | <tr align = " | ||
<td> Toffey Nut Popcorn </td> | <td> Toffey Nut Popcorn </td> | ||
<td> $5.00 </td> | <td> $5.00 </td> | ||
- | <td> <?php print (" | + | < |
- | <td> <?php printf ("$ %4.2f", | + | < |
- | | + | |
</tr> | </tr> | ||
</ | </ | ||
- | <p /> <p /> | + | <p /> |
+ | | ||
<?php | <?php | ||
- | | + | print(" |
- | printf ("Your total bill is: $ %5.2f <br />", | + | printf(" |
- | print ("Your chosen method of payment is: $payment <br />" | + | print(" |
?> | ?> | ||
</ | </ | ||
Line 462: | Line 551: | ||
* Output | * Output | ||
- | {{eg-259:l18-popcorn3-output.png|receipt for Popcorn | + | < |
+ | <h4> Customer: </ | ||
+ | < | ||
+ | <table border = " | ||
+ | < | ||
+ | < | ||
+ | <th> Product </ | ||
+ | <th> Unit Price </ | ||
+ | <th> Quantity Ordered </ | ||
+ | <th> Item Cost </ | ||
+ | </ | ||
+ | <tr align = " | ||
+ | <td> Unpopped Popcorn </ | ||
+ | <td> $3.00 </ | ||
+ | <td> 0 </ | ||
+ | <td> $ 0.00 </ | ||
+ | </ | ||
+ | <tr align = " | ||
+ | <td> Caramel | ||
+ | <td> $3.50 </ | ||
+ | <td> 0 </ | ||
+ | <td> $ 0.00 </ | ||
+ | </ | ||
+ | <tr align = " | ||
+ | <td> Caramel Nut Popcorn </ | ||
+ | <td> $4.50 </ | ||
+ | <td> 0 </ | ||
+ | <td> $ 0.00 </ | ||
+ | </ | ||
+ | <tr align = " | ||
+ | <td> Toffey Nut Popcorn </ | ||
+ | <td> $5.00 </ | ||
+ | <td> 0 </ | ||
+ | <td> $ 0.00 </ | ||
+ | </ | ||
+ | </ | ||
+ | <p /> <p /> | ||
+ | |||
+ | You ordered 0 popcorn items <br />Your total bill is: $ 0.00 <br />Your chosen method of payment is: <br /> | ||
+ | </ | ||
===== Files ===== | ===== Files ===== |
eg-259/lecture18.1259074258.txt.gz · Last modified: 2011/01/14 12:28 (external edit)