【发布时间】:2020-01-01 16:43:24
【问题描述】:
(对不起我的英语不好) 单击按钮后,我正在尝试更改数组中的数量值
我尝试在网络上搜索帮助,但我发现的所有主题都不使用会话以及我在该代码中找到的那一堆东西(我在互联网上找到了该代码)
if (isset($_POST["add_to_cart"])) {
if (isset($_SESSION["shopping_cart"])) {
$item_array_id = array_column($_SESSION["shopping_cart"], "item_id");
if (!in_array($_GET["id"], $item_array_id)) {
$count = count($_SESSION["shopping_cart"]);
$item_array = [
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["quantity"],
];
$_SESSION["shopping_cart"][$count] = $item_array;
} else {
echo '<script>alert("Item Already Added")</script>';
echo '<script>window.location="foodlist.php"</script>';
}
当我点击提交时,这个“add_to_cart”被设置并且所有信息都被发送到另一个页面,但是当我再次点击它以添加另外 1 个项目(我之前点击的同一个项目)时,代码不会产生总和.我在其他方面尝试了很多东西,但即使是我的老师也无法帮助我:/
【问题讨论】:
标签: javascript php arrays session