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 [2012/03/20 08:03] – [Example – Popcorn Sales] 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 ====== | ||
- | **Contact Hour 21**: To be discussed | + | **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 458: | 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 519: | 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 558: | 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.1332230609.txt.gz · Last modified: 2012/03/20 08:03 by eechris