更新$ _SESSION产品数量未更新

问题描述 投票:0回答:1

我正在尝试更新购物车中的产品,但是它不起作用。我不知道问题是什么。

<div class="quantity">
  <input class="input_display" name="aantal" type="number" value="<?=$value['item_quantity'];?>" min="1" max="<?php if($current_max_input_value == 0){ echo $max_input_number; }else{ echo $current_max_input_value; };?>">
</div>
<a href="?action=update&id=<?=$value['item_id'];?>" class="site-btn">Update Item</a>
if(isset($_GET['action'])){
    if($_GET['action'] == 'update'){
        foreach($_SESSION['shopping_cart'] as $key => $item){
            //echo '<pre>';
            //print_r($_SESSION['shopping_cart']);
            //echo '<pre>';
            if($item['item_id'] == $_POST['id']){

                //UPDATE THE ITEM IN SHOPPING CART
                $_SESSION['shopping_cart'][$key]['item_quantity'] = $_POST['aantal'];
            }

        }
    }
}
php session shopping-cart
1个回答
0
投票

这里的问题是,当您使用执行GET调用的<a>时,您没有传递POST变量。而是尝试使用POST vars将按钮Update Item和表单中的“项目数”字段分组。现在,您只能通过PHP脚本中的POST变量获取值,将$ _GET替换为$ _POST。

© www.soinside.com 2019 - 2024. All rights reserved.