我正在为我的电子商务网站创建购物车,但是我的更新查询程序无效。如果我的购物车中有多个产品,那么它不会更新价格和价格。产品数量。如果有一种产品,那么它工作正常。我是php新手。我还附上了购物车的截图。
// cart.php
<?php include_once("header.php");?>
<div id="products_box">
<form action="" method="post" enctype="multipart/form-data">
<table align="center" width="700" bgcolor="#CCFFCC">
<br>
<tr align="center">
<td style="font-family:'Adobe Garamond Pro', 'Times New Roman'; font-size:20px" colspan="4"><h2> Your Book(s) Details </h2></td>
</tr>
<tr align="center" style="font-size:20px; font-family:'Adobe Garamond Pro', 'Times New Roman'">
<th>Remove</th>
<th>Book(s)</th>
<th>Quantity</th>
<th>Total Price</th>
</tr>
<?php
$total=0;
global $con;
$ip = getIp();
$sel_price = "select * from cart where ip_add='$ip'";
$run_price = mysqli_query($con, $sel_price) or die(mysqli_error($con));
while($p_price = mysqli_fetch_array($run_price))
{
$b_id = $p_price['cb_id'];
$b_price = "select * from books where b_id='$b_id'";
$run_book_price = mysqli_query($con, $b_price) or die(mysqli_error($con));
while($pp_price = mysqli_fetch_array($run_book_price))
{
$b_price = array($pp_price['b_price']);
$b_title = $pp_price['b_title'];
$b_image = $pp_price['b_image'];
$single_price = $pp_price['b_price'];
$values = array_sum($b_price);
$total += $values;
?>
<tr align="center">
<td><input type="checkbox" name="remove[]" value="<?php echo $b_id; ?>"/> </td>
<td><h3><a href='details.php?b_id=$b_id' style='text-decoration:none; color: #005680;'><?php echo $b_title; ?></a></h3>
<img src="admin_area/books_images/<?php echo $b_image; ?>" width="100" height="100" />
</td>
<td><input type="text" name="qty" size="8" value=""/></td>
<?php
if(isset($_POST['update_qty']))
{
$qty = $_POST['qty'];
$update_qty = "update cart set qty='$qty'";
$run_qty = mysqli_query($con, $update_qty) or die(mysqli_error($con));
$total = $total*$qty;
}
?>
<td> <?php echo "Rs.\n". $single_price; ?></td>
</tr>
<?php } }?>
<tr align="right">
<td colspan="4"><b> Sub Total: </b></td>
<td colspan="4"><?php echo "Rs.\n". $total; ?></td>
</tr>
<tr>
<td align="left" style="padding-left:12px"><input type="submit" name="remove_pro" value="Remove" style="background: #000000; font-family:'Adobe Garamond Pro Bold', 'Adobe Garamond Pro', 'Adobe Caslon Pro'; font-size:18px; color:#FFFFFF"/></td>
<td align="center" style="padding-right:20px"><input type="submit" name="continue" value="Continue Shopping" style="background: #000000; font-family:'Adobe Garamond Pro Bold', 'Adobe Garamond Pro', 'Adobe Caslon Pro'; font-size:18px; color:#FFFFFF" /></td>
<td align="center" style="padding-left:12px"><input type="submit" name="update_qty" value="Update Quantity" style="background: #000000; font-family:'Adobe Garamond Pro Bold', 'Adobe Garamond Pro', 'Adobe Caslon Pro'; font-size:18px; color:#FFFFFF"/></td>
<td align="right" colspan="4"><input type="submit" name="checkout" value="Checkout" style="background: #000000; font-family:'Adobe Garamond Pro Bold', 'Adobe Garamond Pro', 'Adobe Caslon Pro'; font-size:18px; color:#FFFFFF; margin-right:10px"/></td>
</tr>
</table>
</form>
<?php
global $con;
$ip = getIp();
if(isset($_POST['remove_pro']))
{
foreach($_POST['remove'] as $remove_id)
{
$delete_pro = "delete from cart where cb_id='$remove_id' AND ip_add='$ip'";
$run_query = mysqli_query($con, $delete_pro) or die(mysqli_error($con));
if($run_query)
{
echo "<script>window.open('cart.php','_self')</script>";
}
}
}
if(isset($_POST['continue']))
{
echo "<script>window.open('index.php','_self')</script>";
}
if(isset($_POST['checkout']))
{
echo "<script>window.open('checkout.php','_self')</script>";
}
?>
</div>
</div>
</div>
<!--Content Wrapper Ends--->
<?php include_once("footer.php");?>
<!--Main Wrapper Ends-->
</body>
</html>