Guest User

Untitled

a guest
Jun 22nd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. <?php
  2. //This is the functions.php file
  3. //function pf_validate_number($value, $redirect) {
  4. // if(isset($value)) {
  5. // if(!is_numeric($value)) {
  6. // header('Location: ' . $redirect);
  7. // }
  8. // else {
  9. // $final = $value;
  10. // }
  11. // }
  12. // else {
  13. // $final = 0;
  14. // }
  15. // return $final;
  16. //}
  17.  
  18.  
  19. function showcart() {
  20. if($_SESSION['ordernum']) { //20
  21. if($_SESSION['loggedin']) {
  22. $query = "SELECT id, status FROM orders WHERE customer_id = '" . $_SESSION['userid'] . "' AND status < 2";
  23. echo $query;
  24. $result = mysqli_query($dbc, $query);
  25. $row = mysqli_fetch_array($result);
  26.  
  27. $queryi = "SELECT products.*, orderitems.*, orderitems.id AS itemid FROM products, orderitems WHERE orderitems.product_id = " .
  28. "products.id AND order_id = '" . $row['id'] . "'";
  29. $resulti = mysqli_query($dbc, $queryi);
  30. $numrowsi = mysqli_num_rows($resulti);
  31. }
  32. else {
  33. $query = "SELECT id, status FROM orders WHERE session = '" . session_id() . "' AND status < 2";
  34. $result = mysqli_query($dbc, $query);
  35. $row = mysqli_fetch_array($result);
  36.  
  37. $queryi = "SELECT products.*, orderitems.*, orderitems.id AS itemid FROM products, orderitems WHERE orderitems.product_id = " .
  38. "products.id AND order_id = '" . $row['id'] . "'";
  39. $resulti = mysqli_query($dbc, $queryi);
  40. $numrowsi = mysqli_num_rows($resulti);
  41. } //40
  42. }
  43. else {
  44. $numrowsi = 0;
  45. }
  46.  
  47. if($numrowsi == 0) {
  48. echo 'You have not added anything to your shopping cart yet.';
  49. }
  50. else {
  51. echo '<table cellpadding="10">';
  52. echo '<tr>';
  53. echo '<td></td>';
  54. echo '<td><strong>Item</strong></td>';
  55. echo '<td><strong>Quantity</strong></td>';
  56. echo '<td><strong>Unit Price</strong></td>';
  57. echo '<td><strong>Total Price</strong></td>';
  58. echo '<td></td>';
  59. echo '</tr>';
  60.  
  61. while($rowi = mysqli_fetch_array($resulti)) { //60
  62. $quantitytotal = $rowsi['price'] * $rowsi['quantity'];
  63. echo '<tr>';
  64.  
  65. if(empty($rowi['image'])) {
  66. echo '<td><img src="images/dummy.jpg"></td>';
  67. }
  68. else {
  69. echo '<td><img src="images/' . $rowi['image'] . '"></td>';
  70. }
  71.  
  72. echo '<td>' . $rowi['name'] . '</td>';
  73. echo '<td>' . $rowi['quantity'] . '</td>';
  74. echo '<td><strong>&pound;' . sprintf('%.2f', $quantitytotal) . '</strong></td>';
  75. echo '<td>[<a href="' . $config_basedir . 'delete.php?id=' . $rowi['itemid'] . '">X</a>]</td>';
  76. echo '</tr>';
  77.  
  78. $total = $total + $quantitytotal;
  79. $queryt = "UPDATE orders SET total = '" . $_SESSION['ordernum'] . "'";
  80. $resultt = mysqli_query($dbc, $queryt);
  81. } //80
  82.  
  83. echo '<tr>';
  84. echo '<td></td>';
  85. echo '<td></td>';
  86. echo '<td></td>';
  87. echo '<td>TOTAL</td>';
  88. echo '<td><strong>&pound;' . sprintf('%.2f', $total) . '</strong></td>';
  89. echo '<td></td>';
  90. echo '</tr>';
  91. echo '</table>';
  92. echo '<p><a href="checkoutaddress.php">Go to the checkout</a></p>';
  93.  
  94. }
  95. }
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. ?>
Add Comment
Please, Sign In to add comment