更新 $_SESSION 产品数量未更新
Update $_SESSION product quantity not updating
我正在尝试更新我购物车中的产品,但它不起作用..我不知道问题出在哪里。
<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'];
}
}
}
}
这里的问题是当您使用执行 GET 调用的 <a>
时,您没有传递 POST 变量。相反,请尝试使用 POST vars 将按钮 Update Item
和字段 "number of items" 分组到表单中。现在您只能通过 PHP 脚本中的 POST 变量获取值,将 $_GET 替换为 $_POST.
<form action="cart.php" method="post">
<input type="hidden" name="action" value="update">
<input type="hidden" name="id" value="<?=$value['item_id'];?>">
<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>
<button type="submit" class="site-btn">Update Item</a>
</form>
if(isset($_POST['action'])){
if($_POST['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'];
}
}
}
}
我正在尝试更新我购物车中的产品,但它不起作用..我不知道问题出在哪里。
<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'];
}
}
}
}
这里的问题是当您使用执行 GET 调用的 <a>
时,您没有传递 POST 变量。相反,请尝试使用 POST vars 将按钮 Update Item
和字段 "number of items" 分组到表单中。现在您只能通过 PHP 脚本中的 POST 变量获取值,将 $_GET 替换为 $_POST.
<form action="cart.php" method="post">
<input type="hidden" name="action" value="update">
<input type="hidden" name="id" value="<?=$value['item_id'];?>">
<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>
<button type="submit" class="site-btn">Update Item</a>
</form>
if(isset($_POST['action'])){
if($_POST['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'];
}
}
}
}