2016-03-27 22 views
-1

Bir ürünü satın alındıktan sonra (satın alınan ürünler kullanıcının sepetinden) masamdan nasıl çıkarabilirim? Lütfen bana yardım etmek için ihtiyacınız olan başka bir kod isteyin. Birinin onu satın alır kez kaldırılan ihtiyacı TÜM yani sadece 1 tanesi yoktur bu yüzden the cart table in my dbTablo maddelerini veritabanından kaldırma

temelde tüm ürünler benzersizdir.

<!doctype html> 
 
<html> 
 
<head> 
 
<meta charset="utf-8"> 
 
<title>Untitled Document</title> 
 
<link rel="stylesheet" href="assets/css/styles.css"> 
 

 
<?php 
 
session_start(); 
 
include 'conn.php';?> 
 

 
</head> 
 

 
<body> 
 
<p> <b> <a href="cart.php" >SHOPPING CART</a> - </b> TOTAL ITEMS:<?php total_items();?> TOTAL PRICE: <?php total_price();?> </p> 
 
<?php echo $ip=getip();?> 
 

 
<?php cart(); ?> 
 
<form method="get" action="results.php" enctype="multipart/form-data"> 
 
<input type="text" name="user_search" placeholder="search for products"/> 
 
<input type="submit" name="search" value="search"/> 
 
</form> 
 

 

 

 
<section> 
 
<div class="row"> 
 
<form action="" method="post" enctype="multipart/form-data"> 
 

 
<table class="align-center"> 
 

 
<tr> 
 
<th> Remove </th> 
 
<th> Product(s) </th> 
 

 
<th> Total Price </th> 
 
</tr> 
 
<?php 
 

 
$total = 0; 
 
\t \t global $conn; 
 
\t \t $ip = getip(); 
 
\t \t 
 
\t \t $select_price = " SELECT * FROM cart WHERE ip_add='$ip'"; 
 
\t \t 
 
\t \t $run_price = mysqli_query ($conn, $select_price); 
 
\t \t 
 
\t \t while ($product_price = mysqli_fetch_array ($run_price)){ 
 
\t \t \t 
 
\t \t \t $product_id = $product_price ['product_id']; 
 
\t \t \t $product_price ="SELECT * FROM products WHERE product_id='$product_id'"; 
 
\t \t \t 
 
\t \t \t $run_product_price = mysqli_query($conn, $product_price); 
 
\t \t \t if (!$run_product_price) { 
 
    printf("Error: %s\n", mysqli_error($conn)); 
 
    exit(); 
 
} 
 
\t \t \t 
 
\t \t \t while($pp_price = mysqli_fetch_array ($run_product_price)){ 
 
\t \t \t \t $product_price = array ($pp_price ['product_price']); 
 
\t \t \t \t $product_title = $pp_price ['product_title']; 
 
\t \t \t \t $product_image = $pp_price ['product_image']; 
 
\t \t \t \t $single_price = $pp_price['product_price']; 
 
\t \t \t \t $values = array_sum($product_price); 
 
\t \t \t \t $total +=$values; 
 
\t \t \t \t 
 

 
?> 
 
<tr> 
 
<td> <input type="checkbox" name="remove[]" value="<?php echo $product_id;?>"/> </td> 
 
<td> <?php echo $product_title; ?> <br> 
 
<img src="product_image/<?php echo $product_image; ?>" height="50" width="50"> </td> 
 

 
<td>£<?php echo $values ?></td> 
 

 
</tr> 
 

 

 
<?php } 
 
} 
 
?> 
 
<tr> 
 
<td> <b> Sub Total: </b> </td> 
 
<td> £<?php echo $total ?></td> 
 
</tr> 
 
<tr> 
 
<td><input type="submit" name="update_cart" value="Update Cart"> </td> 
 
<td><input type="submit" name="continue" value="Continue Shopping "> </td> 
 
<td><a href="checkout.php">CHECKOUT </a> </td> 
 

 
</tr> 
 

 
</table> 
 

 
</form> 
 
<?php 
 
\t \t global $conn; 
 

 
$ip = getip(); 
 
if(isset($_POST['update_cart'])){ 
 

 
foreach($_POST['remove'] as $remove_id){ 
 
\t 
 
\t $del_product = "delete from cart where product_id='$remove_id' AND ip_add='$ip'"; 
 
\t 
 
\t $run_del = mysqli_query($conn, $del_product); 
 
\t 
 
\t if($run_del){ 
 
\t \t echo "<script> window.open ('cart.php', '_self') </script>"; 
 
\t } 
 
\t 
 
\t 
 
\t 
 
} 
 
} 
 

 
if(isset($_POST['continue'])){ 
 
echo "<script> window.open ('index.php', '_self') </script>"; 
 
} 
 

 

 

 
?> 
 

 
</section> 
 

 
      
 
</div> 
 
</body> 
 
</html>
yukarıdaki kullanıcıların öğeleri görmek ve PayPal ödemeler için sadece şimdi satın al düğmesi olan kasada gidebilir. O satın alındıktan sonra benim cart.php sayfasıdır (benim db çıkarılmalıdır zaman.

+0

Db'den satırların silinmesini istediğinizden emin misiniz? – Drew

cevap

0

Sen bilmelidir

"DELETE FROM products WHERE product_id='$product_id'" 

çalıştırın bu yöntem o olsa SQL sorguları yapmak SQL enjeksiyonuna açıktır. Parametreli sorguları kullanmaya geçmenizi tavsiye ederim.

+0

Teşekkürler, bunun işe yarayacağını ve bana parametreli sorgular hakkında bilgi verdiğiniz için teşekkür ettiğine inanıyorum. – SCJ