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:05] – [Example – Popcorn Sales Receipt] 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 459: Line 460:
 <code php> <code php>
 <!DOCTYPE html> <!DOCTYPE html>
-<!-- popcorn3.html This describes the popcorn sales form -->+<!-- popcorn3.php Processes the form described in 
 +popcorn3.html 
 +-->
 <html lang="en"> <html lang="en">
   <head>   <head>
     <meta charset="utf-8" />     <meta charset="utf-8" />
-    <title> Popcorn Sales - for PHP handling </title>+    <title> Process the popcorn3.html form </title>
   </head>   </head>
   <body>   <body>
-    <form action = "popcorn3.php+    <?php 
-    method = "post"> +// Get form data values 
-      <h2> Welcome to Millennium Gymnastics Booster Club Popcorn +$unpop=$_POST["unpop"]; 
-      Sales </h2> +$caramel=$_POST["caramel"]; 
-      <table> +$caramelnut=$_POST["caramelnut"]; 
-        <!-- Text widgets for the customer's name and address --> +$toffeynut=$_POST["toffeynut"]; 
-        <tr> +$name=$_POST["name"]; 
-          <td> Buyer's Name: </td> +$street=$_POST["street"]; 
-          <td> +$city=$_POST["city"]; 
-          <input type = "text" name = "name" +$payment=$_POST["payment"]; 
-          size = "30required placeholder="Your name"/> +// If any of the quantities are blank, set them to zero 
-          </td> +if($unpop==""
-        </tr> +$unpop=0; 
-        <tr> +if($caramel=="") 
-          <td> Street Address: </td> +$caramel=0; 
-          <td> +if($caramelnut==""
-          <input type = "textname = "street+$caramelnut=0; 
-          size = "30required placeholder = "Street"/> +if($toffeynut==""
-          </td> +$toffeynut=0; 
-        </tr> +// Compute the item costs and total cost 
-        <tr+$unpop_cost=3.0*$unpop; 
-          <tdCity, State, Zip: </td+$caramel_cost=3.5*$caramel; 
-          <td> +$caramelnut_cost=4.5*$caramelnut; 
-          <input type = "text" name = "city" +$toffeynut_cost=5.0*$toffeynut; 
-          size = "30" required placeholder="City, State, Zip"/> +$total_price=$unpop_cost+$caramel_cost+$caramelnut_cost+$toffeynut_cost; 
-          </td> +$total_items=$unpop+$caramel+$caramelnut+$toffeynut; 
-        </tr+// Return the results to the browser in a table 
-      </table+    ?
-      <p /> +    <h4Customer: </h4
-      <table border = "border"> +    <?php 
-        <!-- First, the column headings --+print("$name <br /> $street <br /> $city <br />"); 
-        <tr> +    ?> 
-          <th> Product </th> +    </> 
-          <th> Price </th> +    <p /> 
-          <th> Quantity </th> +    <table border = "border"> 
-        </tr+      <caption
-        <!-- Now, the table data entries --+        Order Information 
-        <tr> +      </caption> 
-          <td> Unpopped Popcorn (1 lb.) </td> +      <tr> 
-          <td> $3.00 </td> +        <th> Product </th> 
-          <td align = "center"> +        <th> Unit Price </th> 
-          <input type = "number" name = "unpop" +        <th> Quantity Ordered </th> 
-          size = "3" min="0" pattern="\d+/> +        <th> Item Cost </th
-          </td> +      </tr
-        </tr> +      <tr align = "center"
-        <tr> +        <td> Unpopped Popcorn </td> 
-          <td> Caramel Popcorn (2 lb. canister) </td> +        <td> $3.00 </td> 
-          <td> $3.50 </td> +        <td><?php print("$unpop");?></td> 
-          <td align = "center"> +        <td><?php printf("$ %4.2f",$unpop_cost);?></td> 
-          <input type = "number" name = "caramel" +      </tr> 
-          size = "3min="0" pattern="\d+" /> +      <tr align = "center"
-          </td> +        <td> Caramel Popcorn </td> 
-        </tr> +        <td> $3.50 </td> 
-        <tr> +        <td><?php print("$caramel");?></td> 
-          <td> Caramel Nut Popcorn (2 lb. canister) </td> +        <td><?php printf("$ %4.2f",$caramel_cost);?></td> 
-          <td> $4.50 </td> +      </tr> 
-          <td align = "center"> +      <tr align = "center"
-          <input type = "number" name = "caramelnut" +        <td> Caramel Nut Popcorn </td> 
-          size = "3min="0" pattern="\d+" /> +        <td> $4.50 </td> 
-          </td> +        <td><?php print("$caramelnut");?></td> 
-        </tr> +        <td><?php printf("$ %4.2f",$caramelnut_cost);?></td> 
-        <tr> +      </tr> 
-          <td> Toffey Nut Popcorn (2 lb. canister) </td> +      <tr align = "center"
-          <td> $5.00 </td> +        <td> Toffey Nut Popcorn </td> 
-          <td align = "center"> +        <td> $5.00 </td> 
-          <input type = "number" name = "toffeynut" +        <td><?php print("$toffeynut");?></td> 
-          size = "3" min="0" pattern="\d" /> +        <td><?php printf("$ %4.2f",$toffeynut_cost);?></td
-          </td> +      </tr
-        </tr> +    </table
-      </table> +    <p /
-      </> +    </> 
-      <!-- The radio buttons for the payment method --+    <?php 
-      <h3> Payment Method </h3+print("You ordered $total_items popcorn items <br />"); 
-      <p> +printf("Your total bill is: $ %5.2f <br />",$total_price); 
-        <input type = "radio" name = "payment" value = "visa" +print("Your chosen method of payment is: $payment <br />"); 
-        checked = "checked" /> +    ?>
-        Visa +
-        <br /> +
-        <input type = "radio" name = "payment" value = "mc" /> +
-        Master Card +
-        <br /> +
-        <input type = "radio" name = "payment+
-        value = "discover" /> +
-        Discover +
-        <br /> +
-        <input type = "radio" name = "payment" value = "check" /> +
-        Check +
-        <br /> +
-        <br /> +
-        <!-- The submit and reset buttons --> +
-        <input type = "submit" value = "Submit Order" /> +
-        <input type = "reset" value = "Clear Order Form" /> +
-      </p> +
-    </form>+
   </body>   </body>
 </html> </html>
- 
 </code> </code>
  
   * 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.1332230741.txt.gz · Last modified: 2012/03/20 08:05 by eechris