dqwh1203
dqwh1203
2017-01-30 22:05

使添加到购物车按钮适用于简单的网上商店

  • php
  • html

I'm trying to make it so that when the "add" button is pressed on a specific product page the product is added to a $_SESSION.

if(isset($_POST['add'])) {
$_SESSION['cart'] [] = array('product_name' => $result['name'], 'product_price'=> $result['price'], 'product_id' => $result['id']); }

<form method="post">
<input type="submit" class="button blueboxbutton userAccountButton" name="add" value="add"></input></br>
</form>

The above piece of code is working without any problems and it saves the required information without any problems, but items are also added when the page is refreshed. How can I make it so that items are only added to the cart when the "add" button is pressed? I've read many "solutions", but somehow I couldn't get them to work correctly. If any additional information is needed I can post it. Thanks in advance!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答