ausghostdog

process cart

May 29th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. <?php
  2. if(!isset($_SESSION))
  3. {
  4. session_start();
  5. }
  6.  
  7. ?>
  8.  
  9.  
  10.  
  11. <title>shopping cart</title>
  12.  
  13. <link href="http://fonts.googleapis.com/css?family=Abel" rel="stylesheet" type="text/css" />
  14. <link href="../styles/default.css" rel="stylesheet" type="text/css" media="all" />
  15. </head>
  16. <body>
  17.  
  18. <?php
  19.  
  20. if (!isset($_SESSION))
  21. {
  22. session_start();
  23. }
  24.  
  25. require_once "../database/dbconn.php";
  26. require_once "../includes/functions.php";
  27.  
  28.  
  29. $Product_code = $_POST['Product_code'];
  30. $qtyordered = $_POST['qtyordered'];
  31. $Product_price = $_POST['Product_price'];
  32. $Product_name = $_POST['Product_name'];
  33.  
  34.  
  35. $error_message = "";
  36.  
  37. $error_message .= validate_qtyordered($qtyordered);
  38.  
  39. if ($error_message != "")
  40. include_once "../shop/catalogue.php";
  41. else
  42. {
  43. //echo $qtyordered . $Product_price . $Product_code . $Product_name;
  44. //worked here
  45.  
  46. $session_id = session_id();
  47.  
  48.  
  49. $UserID = $_SESSION['UserID'];
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. //worked here
  61. $query = "SELECT * FROM tblcart WHERE session_id = '$session_id' AND UserID = '$UserID' AND Product_code = '$Product_code'";
  62.  
  63. $result = mysql_query($query) or die(mysql_error());
  64.  
  65.  
  66. $rows = mysql_num_rows($result);
  67.  
  68. //$rows = 2; <- set the value twice to test for the mulitpal items in cart
  69. if ($rows > 0)
  70. {
  71. $error_message .= "Product is already in cart";
  72. require_once "../shop/catalogue.php";
  73. }
  74. //worked here
  75.  
  76. else
  77. {
  78. $query = "INSERT into tblcart (session_id, UserID, Product_code, QTY, Product_price) VALUES ('$session_id', '$UserID', '$Product_code', '$qtyordered', '$Product_price')";
  79.  
  80. $result = mysql_query($query) or die(mysql_error());
  81.  
  82. $row = mysql_affected_rows();
  83. if ($row > 0)
  84. {
  85. if ($qtyordered >1)
  86. {
  87. echo $qtyordered . " " . $Product_name . "s have";
  88. }
  89. else
  90. {
  91. echo $qtyordered . " " . $Product_name . " has";
  92. }
  93.  
  94. echo " been added to your cart";
  95. $_SESSION['cart'] = true;
  96. ?>
  97. <p><a href="../shop/catalogue.php"> Continue shopping</a></p>
  98. <p><a href="shopcart.php"> view shopping cart</a></p>
  99. <?php
  100. }
  101. else
  102. {
  103. echo "error";
  104. }
  105. }
  106. }
  107. ?>
  108.  
  109.  
  110. <!--</div>
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. <div id="footer" class="container">
  118. <p>&copy; admin login <a href="../admin/adminlogon.php">here</a></p>
  119. </div>
  120. </body>
  121. </html>
Advertisement
Add Comment
Please, Sign In to add comment