为什么在点击刷新按钮后,数量的值增加1?

时间:2017-04-21 00:29:32

标签: php

<?php       
    foreach ($_SESSION["cart_item"] as $item){
        ?>
                <tr>
                <td style="text-align:left;border-bottom:#F0F0F0 1px solid;"><strong><?php echo $item["nama_produk"]; ?></strong></td>
                <td style="text-align:left;border-bottom:#F0F0F0 1px solid;"><?php echo $item["id_produk"]; ?></td>
                <td style="text-align:right;border-bottom:#F0F0F0 1px solid;"><input type="text" name="quantity" value="<?php echo $item['quantity']; ?>" style="width: 50px"></td>
                <td style="text-align:right;border-bottom:#F0F0F0 1px solid;"><?php echo "Rp. ".$item["harga_produk"]; ?></td>
                <td style="text-align:center;border-bottom:#F0F0F0 1px solid;"><a href="cart.php?action=remove&id_produk=<?php echo $item["id_produk"]; ?>" class="btnRemoveAction">Remove Item</a></td>
                </tr>
                <?php
        $item_total += ($item["harga_produk"]*$item["quantity"]);
        }
        ?>

为什么在点击刷新按钮后,数量的值增加1? 这是购物车项目SESSION:

if(!empty($_SESSION["cart_item"])) {
                if(in_array($productByCode[0]["id_produk"],array_keys($_SESSION["cart_item"]))) {
                    foreach($_SESSION["cart_item"] as $k => $v) {
                            if($productByCode[0]["id_produk"] == $k) {
                                if(empty($_SESSION["cart_item"][$k]["quantity"])) {
                                    $_SESSION["cart_item"][$k]["quantity"] = 0;}
                                $_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"];}}} else {
                    $_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray);
                }
            } else {
                $_SESSION["cart_item"] = $itemArray;}}

before refresh

after refresh

1 个答案:

答案 0 :(得分:-2)

检查脚本流程中的$ _SESSION [“cart_item”]值