以下是我的php代码,显示了如何从购物车中删除物品。网页上没有显示错误,但项目没有删除,购物车没有更新。用完整的代码编辑
<div class="product_box">
<form action="cart.php" method="post" enctype="multipart/data">
<table align="center" width="700" bgcolor="skyblue">
<tr>
<th>Remove</th>
<th>Product (s) </th>
<th>Quantity</th>
<th>Total Price</th>
</tr>
<?php
$total = 0;
global $db;
$ip = getIp();
$sel_price ="select * from cart where ip_add='$ip'";
$run_price = mysqli_query($db, $sel_price);
while ($p_price=mysqli_fetch_array($run_price)) {
$pro_id = $p_price['p_id'];
$pro_price = "select * from products where product_id='$pro_id'";
$run_pro_price = mysqli_query($db, $pro_price);
while ($pp_price = mysqli_fetch_array($run_pro_price)) {
$product_price = array($pp_price ['product_price']);
$product_title = $pp_price['product_title'];
$product_image = $pp_price['product_img1'];
$single_price = $pp_price['product_price'];
$values = array_sum($product_price);
$total +=$values;
//echo "Rs ." . $total;
?>
<tr align="center">
<td><input type="checkbox" name="remove[]"></td>
<td><?php echo $product_title; ?><br>
<img src="admin_area/product_images/<?php echo $product_image;?>" width="50px" height="50px">
</td>
<td><input type="text" name="qty" size="3"></td>
<td><?php echo "Rs." . $single_price ?></td>
</tr>
<?php } } ?>
<tr align="right">
<td colspan="3">
<b> Sub Total: </b>
</td>
<td>
<?php echo "Rs." .$total; ?>
</td>
</tr>
<tr align="center">
<td colspan="1"><input type="submit" name="update_cart" value="Update Cart"></td>
<td><input type="submit" name="continue" value="Continue Shopping"></td>
<td><button><a href="checkout.php">Checkout</a></button></td>
</tr>
</table>
</form>
<?php
$ip = getIp();
if (isset($_POST['update_cart'])) {
foreach ($_POST['remove'] as $remove_id) {
$delete_product = "delete from cart where p_id=".$remove_id." AND ip_add=".$ip;
$run_delete = mysqli_query($db, $delete_product);
if ($run_delete) {
echo "<script>window.open('cart.php','_self')</script>";
}
}
}
}
?>
</div>
</div>
我试图通过在if语句后放置以下代码来检查错误,但是没有用。
else { echo mysqli_error($db);}
请帮忙谢谢。
我得到我的答案,我只是将以下值添加到输入复选框中,并且它可以正常工作。
<input type="checkbox" name="remove[]" value="<?php echo $pro_id; ?> ">
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句