Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.77 KB | None | 0 0
  1. [Back]
  2.  
  3. <?php 
  4. include_once ("Script/Connect.php"); 
  5. include_once("Script/check_log.php"); 
  6. if(!isset($_SESSION['ID'])){ 
  7.     header("location: index.php"); 
  8.     exit(); 
  9. } 
  10.  
  11. $user_costumer = $_SESSION['ID']; 
  12. //These variables declared as global. 
  13. $cart = ''; 
  14. $cart_action = ''; 
  15. $cartArray = ""; 
  16. $cartCount = ""; 
  17. $cartSlice = ""; 
  18. $cartSum="0"; 
  19. $userBalance=""; 
  20. $newBalance=""; 
  21. $file_link = ""; 
  22. $product_name = ""; 
  23. $product_price = ""; 
  24. $cart_top = ""; 
  25. $Q=""; 
  26. $QP=""; 
  27. $newQ=""; //To be used later 
  28. $cart_bottom = ""; 
  29. $cart_id = ""; 
  30. $sql2 = mysql_query("SELECT * FROM checkout WHERE U_ID='$user_costumer'")or die(mysql_error()); 
  31. $count = mysql_num_rows($sql2); 
  32. if($count > 0){ 
  33.     while($row = mysql_fetch_array($sql2)){ 
  34.         $cart_shop = $row["Cart"]; 
  35.         $cart_id = $row["ID"]; 
  36.         $Q=$row['Quantity']; 
  37.         if($cart_shop != '') 
  38.         { 
  39.             $cart_action = 
  40.                 <form action="shopping_cart.php" method="post" enctype="multipart/form-data"> 
  41.                 <input type="submit" name="submit" class="cart_action_yes" value="Check out" />'; 
  42.         } 
  43.         else 
  44.         { 
  45.             $cart_action = '<div class="cart_action_none">Check out</div>'; 
  46.         } 
  47.         if ($cart_shop  != "") 
  48.         {  
  49.             $cartArray = explode(",", $cart_shop); 
  50.             $cartCount = count($cartArray); 
  51.             $cartSlice = array_slice($cartArray, 0, 50);     
  52.             $i = 0;  
  53.             foreach ($cartSlice as $key => $value) 
  54.             {  
  55.                 $i++;  
  56.                 $file_link = 'Catgs/' . $value . '.jpg'; 
  57.                 $image = '<img src="' . $file_link . '" width="40" height="40" border="0" />'; 
  58.                 $sql3 = mysql_query("SELECT Name, Price FROM mobiles WHERE id='$value'") or die ("Sorry we had a mysql error!");
  59.                 while($row = mysql_fetch_array($sql3)){  
  60.                     $product_name = $row["Name"]; 
  61.                      $product_price = $row["Price"]; 
  62.                      $QP=$Q*$product_price; 
  63.                      $cartSum+= $product_price; 
  64.             }                 
  65.                 $cart_top = 
  66.                     <table width="90%" cellpadding="3" cellspacing="0" border="1"> 
  67.                         <tr> 
  68.                             <td width="40" align="center" height="40"></td> 
  69.                             <td>Product name</td> 
  70.                             <td width="70" align="center">Quantity</td> 
  71.                             <td width="40" align="center">Price</td> 
  72.                              
  73.                         </tr> 
  74.                 '; 
  75.                 $cart .= 
  76.                     <tr> 
  77.                         <td width="45" align="center" height="40"><a href="view.php?id=' . $value . '">' . $image . '</a></td> 
  78.                         <td><p class="text">' . $product_name .'</p></td> 
  79.                         <td align="center"><input type="text" class="text_input" style="width: 20px;" maxlength="2" value="'.$Q.'"/><br/> 
  80.                         <input type="submit" value="Update"/></td> <-- Here 
  81.                         </td> 
  82.                          
  83.                         <td width="70" align="center"><p class="price"> ' . $QP .' JOD</p></td> 
  84.                     </tr> 
  85.                 ';   
  86.                 $cart_bottom = 
  87.                     <tr> 
  88.                         <td colspan="3" style="padding: 3px;"><h3>Total price: </h3></td> 
  89.                         <td width="70" align="center"><p class="price"> ' . $cartSum .' JOD</p></td> 
  90.                     </tr> 
  91.                     </table> 
  92.                 '; 
  93.             } 
  94.         } 
  95.     } 
  96. }else{ 
  97.     $cart = "<b>In this moment you don't have a shopping cart, in order to have one go buy something.</b>"; 
  98. } 
  99. /*$BSQL=mysql_query("Select Balance from users where ID='$user_costumer'") or die (mysql_error()); 
  100. while($row=mysql_fetch_array($BSQL)) 
  101.     $userBalance=$row["Balance"]; 
  102.  
  103.     if($userBalance<$cartSum) 
  104.     echo '<p style="color:red"> Fetch error, please be back later<p>'; 
  105. else  
  106. $newBalance=$userBalance-$cartSum; 
  107. if(isset($_POST['submit'])){ 
  108.     $sql = mysql_query("UPDATE users SET Balance='$newBalance' WHERE ID='$user_costumer' ") or die (mysql_error()); 
  109. $cart_action='<p style="color:red">Thanks for your shopping! Have a nice day!<p>'; 
  110. }*/ 
  111. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement