<div class="container"> <div class="row"> <form action="" method="post"> <table class="table table-border text-center w-auto m-auto"> <thead> <tr> <th> Shoe name</th> <th> Shoe image </th> <th> Quantity</th> <th> Total price</th> <th> Remove Item</th> <th colspan="2"> Operations</th> </tr> </thead> <tbody> <!-- PHP to display dynamic datas from cart--> <?php global $conn; $get_ip_address = getIPAddress(); $total_price=0; $cart_query="select * from `cart_details` where ip_address='$get_ip_address'"; $result=mysqli_query($conn,$cart_query); while($row=mysqli_fetch_array($result)){ $shoe_id=$row['shoe_id']; $select_products="select * from `products` where shoe_id='$shoe_id'"; $result_shoes=mysqli_query($conn,$select_products); while($row_shoe_price=mysqli_fetch_array($result_shoes)){ $shoe_price=array($row_shoe_price['shoe_price']); $price_table=$row_shoe_price['shoe_price']; $shoe_name=$row_shoe_price['shoe_name']; $shoe_image1=$row_shoe_price['shoe_image1']; $shoe_values=array_sum($shoe_price); $total_price+=$shoe_values; ?> <tr> <td><?php echo $shoe_name?></td> <td><img src="./admin_area/product_images/<?php echo $shoe_image1?>" class="cart_img"alt=""></td> <td><input type="text" name="qty" class="form-input w-50"></td> <!-- Code for update cart --> <?php $get_ip_address = getIPAddress(); if(isset($_POST['update_item'])){ $quantities=$_POST['qty']; $update_cart="update `cart_details` set quantity=$quantities where ip_address='$get_ip_address'"; $result_shoe_quantity=mysqli_query($conn,$update_cart); $total_price=$total_price*$quantities; }?> <td><?php echo $price_table?></td> <td><input type="checkbox" name="removeitem[]" value="<?php echo $shoe_id?>"></td> <td> <!--<button class="bg-primary text-light m-2 px-3 border-0">update</button>--> <input type="submit" value="Update Item" class="bg-primary text-light m-2 px-3 border-0" name="update_item"> <input type="submit" value="Remove Item" class="bg-primary text-light m-2 px-3 border-0" name="remove_item"> </td> </tr> <?php }} ?> </tbody> </table> <div class="d-flex"> <h4 class="px-3" style="font-size: 20px;">Total Amount: PHP <?php echo $total_price?></h4> <a href="shopnow.php"><button class="bg-secondary text-light m-2 px-3 border-0">Continue Shopping</button></a> <a href="#"><button class="bg-primary text-light m-2 px-3 border-0">Proceed to Checkout</button></a> </div> </div> </div> </form>
$the_var = $row['field']; // or $the_var = $_POST['field'] are useless. It's just reallocation of value, a swap between two var. It's useless to have values in redundant dublets.
select * from `products` where shoe_id IN ( select * from `cart_details` where ip_address='$get_ip_address() );
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)