User Tools

Site Tools


eg-259:lecture18

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
eg-259:lecture18 [2012/03/20 08:03] – [Example – Popcorn Sales] eechriseg-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 on Tuesday 27th March, 2012.+**Supplementary Material** 
 + 
 +Provided for Reference. This material is no longer taught on this module.
  
 **Lecturer**: [[C.P.Jobling@Swansea.ac.uk|Dr Chris P. Jobling]]. **Lecturer**: [[C.P.Jobling@Swansea.ac.uk|Dr Chris P. Jobling]].
  
 Using PHP for web applications development. Using PHP for web applications development.
- 
  
  
Line 227: Line 228:
  
     * If the query string has ''colour=light&taste=malty''     * If the query string has ''colour=light&taste=malty''
-    * ''$_POST["colour")'' will return ''"light"'' and ''$_POST["taste")'' will return ''"malty"'' +    * ''$_POST["colour"]'' will return ''"light"'' and ''$_POST["taste"]'' will return ''"malty"'' 
     * Query matching will also turn check box group ''colour=red&colour=blue'' to an array so that ''$_POST["colour"]'' returns the right thing.      * Query matching will also turn check box group ''colour=red&colour=blue'' to an array so that ''$_POST["colour"]'' returns the right thing. 
  
Line 458: Line 459:
 ---- ----
 <code php> <code php>
-<?php echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); ?>  +<!DOCTYPE html>
-<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1 //EN" +
- "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +
 <!-- popcorn3.php - Processes the form described in <!-- popcorn3.php - Processes the form described in
-     popcorn3.html +popcorn3.html 
-     --> +--> 
-<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang="en">+<html lang="en">
   <head>   <head>
 +    <meta charset="utf-8" />
     <title> Process the popcorn3.html form </title>     <title> Process the popcorn3.html form </title>
   </head>   </head>
   <body>   <body>
     <?php     <?php
- 
 // Get form data values // Get form data values
- +$unpop=$_POST["unpop"]; 
-      $unpop = $_POST["unpop"]; +$caramel=$_POST["caramel"]; 
-      $caramel = $_POST["caramel"]; +$caramelnut=$_POST["caramelnut"]; 
-      $caramelnut = $_POST["caramelnut"]; +$toffeynut=$_POST["toffeynut"]; 
-      $toffeynut = $_POST["toffeynut"]; +$name=$_POST["name"]; 
-      $name = $_POST["name"]; +$street=$_POST["street"]; 
-      $street = $_POST["street"]; +$city=$_POST["city"]; 
-      $city = $_POST["city"]; +$payment=$_POST["payment"];
-      $payment = $_POST["payment"]; +
 // If any of the quantities are blank, set them to zero // If any of the quantities are blank, set them to zero
- +if($unpop=="") 
-      if ($unpop == "") $unpop = 0; +$unpop=0; 
-      if ($caramel == "") $caramel = 0; +if($caramel=="") 
-      if ($caramelnut == "") $caramelnut = 0; +$caramel=0; 
-      if ($toffeynut == "") $toffeynut = 0; +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; 
-      $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 ("$name <br /> $street <br /> $city <br />");+print("$name <br /> $street <br /> $city <br />");
     ?>     ?>
-    <p /> <p /> +    <p /> 
-<table border = "border"> +    <p /> 
-      <caption> Order Information </caption>+    <table border = "border"> 
 +      <caption> 
 +        Order Information 
 +      </caption>
       <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 ("$unpop"); ?> </td> +        <td><?php print("$unpop");?></td> 
-        <td> <?php printf ("$ %4.2f", $unpop_cost); ?> +        <td><?php printf("$ %4.2f",$unpop_cost);?></td>
-        </td>+
       </tr>       </tr>
       <tr align = "center">       <tr align = "center">
         <td> Caramel Popcorn </td>         <td> Caramel Popcorn </td>
         <td> $3.50 </td>         <td> $3.50 </td>
-        <td> <?php print ("$caramel"); ?> </td> +        <td><?php print("$caramel");?></td> 
-        <td> <?php printf ("$ %4.2f", $caramel_cost); ?> +        <td><?php printf("$ %4.2f",$caramel_cost);?></td> 
-        </td> +      </tr>
-        </tr>+
       <tr align = "center">       <tr align = "center">
         <td> Caramel Nut Popcorn </td>         <td> Caramel Nut Popcorn </td>
         <td> $4.50 </td>         <td> $4.50 </td>
-        <td> <?php print ("$caramelnut"); ?> </td> +        <td><?php print("$caramelnut");?></td> 
-        <td> <?php printf ("$ %4.2f", $caramelnut_cost); ?> +        <td><?php printf("$ %4.2f",$caramelnut_cost);?></td>
-        </td>+
       </tr>       </tr>
       <tr align = "center">       <tr align = "center">
         <td> Toffey Nut Popcorn </td>         <td> Toffey Nut Popcorn </td>
         <td> $5.00 </td>         <td> $5.00 </td>
-        <td> <?php print ("$toffeynut"); ?> </td> +        <td><?php print("$toffeynut");?></td> 
-        <td> <?php printf ("$ %4.2f", $toffeynut_cost); ?> +        <td><?php printf("$ %4.2f",$toffeynut_cost);?></td>
-        </td>+
       </tr>       </tr>
     </table>     </table>
-    <p /> <p /> +    <p /> 
 +    <p />
     <?php     <?php
-      print ("You ordered $total_items popcorn items <br />"); +print("You ordered $total_items popcorn items <br />"); 
-      printf ("Your total bill is: $ %5.2f <br />", $total_price); +printf("Your total bill is: $ %5.2f <br />",$total_price); 
-      print ("Your chosen method of payment is: $payment <br />");+print("Your chosen method of payment is: $payment <br />");
     ?>     ?>
   </body>   </body>
Line 558: Line 551:
   * Output   * Output
  
-{{eg-259:l18-popcorn3-output.png|receipt for Popcorn oder}}+<html> 
 +        <h4> Customer</h4> 
 +     <br />  <br />  <br />    <p /> <p /> 
 +<table border = "border"> 
 +      <caption> Order Information </caption> 
 +      <tr> 
 +        <th> Product </th> 
 +        <th> Unit Price </th> 
 +        <th> Quantity Ordered </th> 
 +        <th> Item Cost </th> 
 +      </tr> 
 +      <tr align = "center"> 
 +        <td> Unpopped Popcorn </td> 
 +        <td> $3.00 </td> 
 +        <td> 0 </td> 
 +        <td> $ 0.00        </td> 
 +      </tr> 
 +      <tr align = "center"> 
 +        <td> Caramel Popcorn </td> 
 +        <td> $3.50 </td> 
 +        <td> 0 </td> 
 +        <td> $ 0.00        </td> 
 +        </tr> 
 +      <tr align = "center"> 
 +        <td> Caramel Nut Popcorn </td> 
 +        <td> $4.50 </td> 
 +        <td> 0 </td> 
 +        <td> $ 0.00        </td> 
 +      </tr> 
 +      <tr align = "center"> 
 +        <td> Toffey Nut Popcorn </td> 
 +        <td> $5.00 </td> 
 +        <td> 0 </td> 
 +        <td> $ 0.00        </td> 
 +      </tr> 
 +    </table> 
 +    <p /> <p /> 
 + 
 +    You ordered 0 popcorn items <br />Your total bill is: $  0.00 <br />Your chosen method of payment is:  <br /> 
 +</html>
  
 ===== Files ===== ===== Files =====
eg-259/lecture18.1332230609.txt.gz · Last modified: 2012/03/20 08:03 by eechris