Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta name="Author" content="Richard Bowen">
- <link rel="stylesheet" href="css/style.css" type="text/css" />
- <title>Homemade Jams e-Retail prototype - Order Summary</title>
- </head>
- <body>
- <h2>Order Summary</h2>
- <hr>
- <form method="post" action="save_purchases.php">
- <?php
- //error_reporting(0);
- //Establish connection to SQL server in order to take information from the database
- require "connect.php";
- // In this program we get the customer name sent from the form and then
- // for each of the items chosen we match with the database, keep a runnning
- // total of the cost and confirm the details back to the visitor
- //Define Customer email as entered on order summary page
- $custemail = $_POST['emailgiven'];
- echo "<br>custemail: ";
- echo "$custemail";
- //Times looped
- $numberofitemspurchased = 0;
- //Define values for quantities as entered on previous page
- //Come back at the end > change these 10 manual ones to $_POST[]
- $QTY = array($_POST['q1'], $_POST['q2'], $_POST['q3'], $_POST['q4'], $_POST['q5'], $_POST['q6'], $_POST['q7'], $_POST['q8'], $_POST['q9'], $_POST['q10']);
- //$CHK = array($_POST[0], $_POST['tk2'], $_POST['tk3']);
- echo "<br>QTY1";
- echo "$QTY[0]";
- echo "<br>QTY2";
- echo "$QTY[1]";
- echo "<br>QTY3";
- echo "$QTY[2]";
- //Define subtotal array
- $subtotal = array();
- //Define query
- //Selecting all item queries from tables "items" and "jamtypes"
- $query = "SELECT i.*, jt.* FROM items i, jamtypes jt WHERE i.JamTypeID = jt.JamTypeID";
- //$query = "SELECT ItemID, ItemDescription, ItemName, ItemPrice, ItemWeight FROM `items`";
- $result = $db->query($query);
- echo "<p>You selected:</p>";
- //Defining variable total before the loop in case there are no items and loop never gets executed
- $total=0.00;
- while ($row = mysqli_fetch_array ($result))
- {
- // this extracts data out of database
- extract ($row);
- // this reads through the data sent by the form
- foreach ($_POST as $varname => $varvalue)
- {
- //Define temporary variable and adjust to align with variable array
- //$i is the item number the user bought on previous page
- $i = $ItemID - 1;
- //VALIDATION - I want to ignore Quantities that aren't whole integers above zero
- //To avoid unwanted listings when listing back to the user
- //First I'm only continuing if the data that was submitted on the previous form in the quantity field is an integer
- if (ctype_digit($QTY[$i]))
- {
- //Now we know it's an integer...
- //I'm checking to make the value is not 0 in order to progress through the code
- if (!empty($QTY[$i]))
- {
- //Match form selection with database
- if ($ItemID==$varname)
- {
- //echo "<a href=$item_img_url>click here for image</a>
- echo "<br>item id: ", $ItemID, "<br>";
- echo "<td><img src='", $ItemImage, "' alt='", $ItemName, "' height='128' width='128'></td>";
- echo "<br>";
- echo $QTY[$i], "x ", $ItemName, " ", $JamType, " at <i>£", $ItemPrice, "0</i> each";
- echo "<br>";
- //Format number to 2 decimal places (proper currency formatting)
- $subtotal[$i]= $QTY[$i] * $ItemPrice;
- $subtotal[$i] = number_format($subtotal[$i], 2);
- echo " <b>£", $subtotal[$i], "</b><br><br>";
- //$confirmeditem = array();
- //$confirmedqty = array();
- //$confirmeditem[$timeslooped] = $ItemID;
- //$confirmedqty[$timeslooped] = $QTY[$i];
- //$ItemID
- echo "<input type='hidden' name='itm$numberofitemspurchased' value = $ItemID>";
- echo "<input type='hidden' name='qty$numberofitemspurchased' value = $QTY[$i]>";
- echo "<input type='hidden' name='emailgiven' value = $custemail>";
- $total=$total+$subtotal[$i];
- //echo "<br>timeslooped: ";
- //$timeslooped++;
- //echo "<br>timeslooped: ";
- //++$timeslooped;
- $numberofitemspurchased = $numberofitemspurchased + 1;
- }
- }
- }
- }
- }
- echo "<br><b>Total sum: £";
- $total = number_format($total, 2);
- echo $total;
- //Calculate and Display VAT @ 20%
- $VAT = $total * 0.2;
- $VAT = number_format($VAT, 2);
- echo "<br>Plus 20% VAT: £", $VAT, "</b>";
- //Calculate & Display Grand Total
- $GRAND = $total + $VAT;
- $GRAND = number_format($GRAND, 2);
- echo "<br><h3>Grand Total: ";
- echo "£", $GRAND, "</h3>";
- echo "<input type='hidden' name='arraylength' value=$numberofitemspurchased>";
- // mysqli_close($connection);
- ?>
- <br>
- <br>
- <!-- This creates a button on the form which, when clicked causes the action, above, to happen -->
- <input type="submit" value="Confirm Purchases">
- </form>
- </body>
- <footer>
- <hr>
- <p>
- Check valid HTML 5:<br>
- <a href="http://validator.w3.org/check?uri=referer">
- <img src="images/check-valid-html5.png" alt="Valid HTML 5" height="36" width="94"></a>
- </p>
- <a href="home.php">Return to home page</a><br>
- Richard Bowen 13040615 eBusiness © 2017
- </footer>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement