Last Updated: November 17, 2017
·
706
· husnain00789

I'm facing problem with my ecommerce cms cart page i need help anyone.

The problem is when i change the quantity of product and click to update cart my price update correctly but quantity come back to first quantity. For example if quantity is written 2 in cart page and i change it to 4 or 6 etc. and then when i click update cart everything done correctly except quantity the quantity again come back to 2 . i hope you understand.

there is my codes of cart page

<?php
session_start();

include 'includes/head.php';
include 'functions/functions.php';
include 'includes/navigation.php';
include 'includes/searchbar.php';

?>
<div class="container">
<form action="cart.php" method="post" enctype="multipart/form-data">
<h1 style="padding:30px">Your Shopping Cart</h1>
<div class="table-responsive">

<table style="border: 1px solid rgba(0,0,0,.1); border-radius:20px;" class="table border">
<thead>
<tr>
<th>Remove</th>
<th>Product picture</th>
<th>Title</th>
<th>Qty</th>
<th>Price</th>

  </tr>
</thead>
<tbody>
 <?php
    $total = 0;

global $con;
$ip = getIp();
$selprice = "select * from cart where ipadd= '$ip'";
$runprice = mysqliquery($con, $selprice);
while($p
price = mysqlifetcharray($runprice)){
$pro
id = $pprice['pid'];
$proprice = "select * from products where productid = '$proid'";
$run
proprice = mysqliquery($con, $proprice);
while($pp
price = mysqlifetcharray($runproprice)){
$productprice = array($ppprice['productprice']);
$product
title = $ppprice['producttitle'];
$productimage = $ppprice['productimage'];
$single
price = $ppprice['productprice'];
$values = arraysum($productprice);
$total +=$values;
?>
<tr>

<td><input type="checkbox" name="remove[]" class="remove" value="<?php echo $pro_id; ?>"/></td>
<td><img src="admin_area/product_image/<?php echo $product_image; ?>" width="auto" height="45"/></td>
<td><?php echo $product_title; ?></td>

<!-- quantity update input -->
<td><input type="text" style="width:60px;" size="4" name="qty" value="<?php echo $_SESSION['qty']; ?>" /></td>

<!-- quantity update function -->
<?php
if(isset($POST['updatecart'])){
$qty = $POST['qty'];
$update
qty = "update cart set qty='$qty'";
$runqty = mysqliquery($con, $updateqty);
$
SESSION['qty']=$qty;
$total = $total*$qty;
}
?> <td><?php echo "$" . $single_price; ?></td>
</tr> <?php }} ?>

<!-- cart update button -->

 <tr align="right"><td colspan="5"><input type="submit" name="update_cart" value="Update Cart" class=" btn-checkout"/></td></tr>
</tbody>

</table>

<div style="width:400px; float: right;">
<h1>Cart Total</h1>
<table style="border:1px solid grey;" class="table">
<tbody>
<tr>
<th>Subtotal </th>
<td><?php echo "$" . $total; ?></td>
</tr>
<tr align="right"><td colspan="2"><button type="button" class="btn-checkout"><a href="checkout.php" style="text-decoration: none; color:black;">Checkout >></a></button></td></tr>

</tbody>
</table>
</div>
</form>