Guest User

Untitled

a guest
Mar 21st, 2016
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if(!isset($_SESSION["Username"]))
  4. {
  5. echo "";
  6. }
  7. if(isset($_SESSION["Username"]))
  8. {
  9. $Username=$_SESSION["Username"];
  10. $conn=mysqli_connect('localhost','root','','alpha');
  11. $user_id=mysqli_query($conn,"SELECT * FROM customers WHERE Username='$Username'");
  12. while ( $row=mysqli_fetch_assoc($user_id))
  13. {
  14. $user=$row['customer_id'];
  15. }
  16. /*
  17. $conn=mysqli_connect('localhost','root','','alpha');
  18. $sql=mysqli_query($conn,"SELECT COUNT(user_id) as total FROM customers
  19. WHERE Username='$Username' AND pass='$Password'");
  20. $row=mysqli_fetch_assoc($query);
  21. if($row['total'] <= 0)
  22. {
  23.  
  24. }
  25. */
  26. }
  27. ?>
  28. <?php
  29. $conn=mysqli_connect('localhost','root','','alpha');
  30. if(isset($_GET['id'])){
  31. $id=preg_replace('#[^0-9]#i','',$_GET['id']);
  32. $sql=mysqli_query($conn,"SELECT * FROM products WHERE product_id='$id' LIMIT 1");
  33. $product_count=mysqli_num_rows($sql);
  34. if($product_count>0)
  35. {
  36. while ( $row=mysqli_fetch_assoc($sql))
  37. { $id=$row['product_id'];
  38. $name=$row['name'];
  39. $price=$row['price'];
  40. $category=$row['category'];
  41. $sub_cat=$row['sub_category'];
  42. $brand=$row['brand'];
  43. $details=$row['details'];
  44. }
  45. }
  46. else{
  47. echo "ITEM Doesn't Exist";
  48. exit();
  49. }
  50. }
  51.  
  52. else
  53. {
  54. echo "wrong id";
  55. exit();
  56. }
  57. ?>
  58. <!DOCTYPE html>
  59. <html>
  60. <head>
  61. <title>ALPHA ELEX</title>
  62. </head>
  63. <body>
  64. <div>
  65. <?php
  66. include 'Menu.php';
  67. ?>
  68. </div>
  69. <div id="PageContent">
  70. <p><table>
  71. <tr>
  72. <td width="40%" align="center"><?php echo '<img src="uploads/'.$name.'.jpeg" width="90%">';
  73. echo'<br><a href="uploads/'.$name.'.jpeg"><b><h4>View Full Size</h4></b></a>';?></td>
  74. <td>
  75. <?php echo '<b>'.$name. "<br>INR" .$price."<br>".$category."<br>".$sub_cat."<br>".$brand."<br>".
  76. $details."<br></b>";
  77. ?>
  78. <form method="POST" action="product.php?id=<?php echo $id;?>">
  79. <input type="hidden" value="<?php echo $id;?>" name="pid"/>
  80. <input type="number" name="quantity" placeholder="quantity(1)" required=""/><br><br><br>
  81. <button type="submit" value="" name="addtocart" class="btn btn-primary">ADD TO CART</button>
  82. </form>
  83. </td>
  84. </tr>
  85. </table>
  86. </p>
  87.  
  88. </div>
  89. <div id="PageFooter"></div>
  90.  
  91. </body>
  92. </html>
  93.  
  94. <?php
  95. if(isset($_POST['addtocart']))
  96. {
  97. if( isset($_SESSION["Username"])){
  98. $conn=mysqli_connect('localhost','root','','alpha');
  99. $customer_id=$user;
  100. $product_id=$id;
  101. $quantity=$_POST['quantity'];
  102. $total_price=$price * $quantity;
  103. $payment_method="NOT DEFINED";
  104. $date = date('Y-m-d',strtotime('+1 Week') );
  105. $duplicates=mysqli_query($conn,"SELECT * FROM orders WHERE customer_id='$customer_id' AND
  106. product_id='$product_id'
  107. AND date_of_delivery='$date'");
  108. /*$duplicate_count=mysqli_num_rows($duplicates);
  109. if ($duplicate_count>0) {
  110. $quantity_update=mysqli_query($conn,"UPDATE orders SET quantity='$quantity',
  111. total_price='$total_price'
  112. WHERE customer_id='$customer_id' AND
  113. product_id='$product_id'
  114. AND date_of_delivery='$date'
  115. ");
  116. if($quantity_update===true)
  117. echo "<div align='center'><b>
  118. ALREADY IS IN YOUR CART/ORDERS WE CHANGED THE QUANTITY TO ".$quantity."</b></div>";
  119. }*/
  120.  
  121. $query=mysqli_query($conn,"INSERT INTO orders
  122. (customer_id,product_id,quantity,total_price,payment_method,
  123. date_of_delivery)
  124. VALUES ('$customer_id',
  125. '$product_id',
  126. '$quantity',
  127. '$total_price',
  128. '$payment_method',
  129. '$date')");
  130. if ($query === false)
  131. {
  132. echo "ERROR";
  133. }
  134. else
  135. {
  136. echo "<div align='center'><b>PRODUCT ADDED TO CART<br><a href='index.php'>CONTINUE SHOPPING</a><br>
  137. <a href='cart.php'>CHECKOUT</a></b></div>";
  138.  
  139. }
  140.  
  141. }
  142. else{
  143. header("location: Login.php");
  144. }
  145. }
  146.  
  147. ?>
Add Comment
Please, Sign In to add comment