我如何修复我的更新数量在我的购物车页面


How do i fix my update quantity in my cart page?

这些代码来自我的购物车页面。如果我更新数量,总价是乘而不是加或减。

<tr align="center">
    <td> <button name="remove[]" onclick="returnshow_confirm();" value="<?php echo $prod_id; ?>">Remove </button></td>
    <td><?php   echo $prod_name; ?><br /> <img src="images/<?php echo $prod_image; ?>" width="60" height="60" /></td>
    <td><input type="text" size="4" name = "qty" value = "" /></td>
    <-- here are the part of update--->
    <?php
        if(isset($_POST['qty'])){
            $asd = $_POST['qty'];
            $update_qty = "update cart set qty = '$asd'";
            $run_qty = mysqli_query($con, $update_qty);
            $_SESSION['qty'] = $qty;
            $total = $total*$qty;           
            echo "<script>windows.open('cart.php',_self)</script>";
        }
        <--- to here --->
    ?>
    <td><?php echo "Php ".$single_price;  ?></td>        
</tr>*/

您没有声明$qty但在会话e-g中赋值$_SESSION['qty'] = $qty;你应该试试$ _SESSION(的数量)= $ asd;

您在哪一行得到错误并更改这一行$check_pro = "select * from cart where ip_add='$ip' AND p_id ='$ pro_id'来$check_pro = "select * from cart where ip_add=' ' .$ip. ' ' 'AND p_id = ' ' .$pro_id. ' '"‘和单引号一样,你不能指定变量,它认为它是字符串