Guest User

Untitled

a guest
Jul 3rd, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. <?php
  2. // create short variable names
  3. $tireqty = $_POST['tireqty'];
  4. $oilqty = $_POST['oilqty'];
  5. $sparkqty = $_POST['sparkqty'];
  6. $address = $_POST['address'];
  7. $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
  8. $date = date('H:i, jS F Y');
  9. ini_set('display_errors', 1);
  10. error_reporting(E_ALL);
  11. ?>
  12. <html>
  13. <head>
  14. <title>Bob's Auto Parts - Order Results</title>
  15. </head>
  16. <body>
  17. <h1>Bob's Auto Parts</h1>
  18. <h2>Order Results</h2>
  19. <?php
  20.  
  21. echo "<p>Order processed at ".date('H:i, jS F Y')."</p>";
  22.  
  23. echo "<p>Your order is as follows: </p>";
  24.  
  25. $totalqty = 0;
  26. $totalqty = $tireqty + $oilqty + $sparkqty;
  27. echo "Items ordered: ".$totalqty."<br />";
  28.  
  29.  
  30. if ($totalqty == 0) {
  31.  
  32. echo "You did not order anything on the previous page!<br />";
  33.  
  34. } else {
  35.  
  36. if ($tireqty > 0) {
  37. echo $tireqty." tires<br />";
  38. }
  39.  
  40. if ($oilqty > 0) {
  41. echo $oilqty." bottles of oil<br />";
  42. }
  43.  
  44. if ($sparkqty > 0) {
  45. echo $sparkqty." spark plugs<br />";
  46. }
  47. }
  48.  
  49.  
  50. $totalamount = 0.00;
  51.  
  52. define('TIREPRICE', 100);
  53. define('OILPRICE', 10);
  54. define('SPARKPRICE', 4);
  55.  
  56. $totalamount = $tireqty * TIREPRICE
  57. + $oilqty * OILPRICE
  58. + $sparkqty * SPARKPRICE;
  59.  
  60. $totalamount=number_format($totalamount, 2, '.', ' ');
  61.  
  62. echo "<p>Total of order is $".$totalamount."</p>";
  63. echo "<p>Address to ship to is ".$address."</p>";
  64.  
  65. $outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil\t"
  66. .$sparkqty." spark plugs\t\$".$totalamount
  67. ."\t". $address."\n";
  68.  
  69.  
  70.  
  71. // open file for appending
  72. $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab');
  73.  
  74. flock($fp, LOCK_EX);
  75.  
  76. if (!$fp) {
  77. echo "<p><strong> Your order could not be processed at this time.
  78. Please try again later.</strong></p></body></html>";
  79. exit;
  80. }
  81.  
  82. fwrite($fp, $outputstring, strlen($outputstring));
  83. flock($fp, LOCK_UN);
  84. fclose($fp);
  85.  
  86. echo "<p>Order written.</p>";
  87. ?>
  88. </body>
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment