-3
Good morning, when adding a product to your cart every time you update your browser it increases the product by +1. How to prevent this? This is how to add it:
//adiciona produto
if(isset($_GET['acao'])){
$id = intval($_GET['id']);
if(!isset($_SESSION['shop'][$id])){
$_SESSION['shop'][$id] = 1;
}else{
$_SESSION['shop'][$id] += 1;
}
}
I would recommend you use Ajax to add in the cart, so you would have no problem with arguments passed in the url.
– Miguel Batista
You are talking about the same product being added multiple times or the quantity of the product ?
– Diego Souza
You can add both the product and quantity via AJAX, the difference is that it will increment whenever the user clicks a button and not when the page is loaded. In the PHP file you check if the product is in the session, if yes increments, if not adds.
– Miguel Batista
After adding you can redirect it to the cart page without passing the action parameter, for example:
header('Location: carrinho.php');
, ai when the user refreshes the page, will not enter if, not adding an amount to the cart, or else, use ajax...– Guilherme Lopes
Possible duplicate of Refresh-free browsing!
– Wallace Maxters
I don’t understand the duplicate vows. What does Ajax have to do with it? You want the person to do it in ajax just to avoid the problem?
– Bacco
@Bacco is not that crazy, but perhaps because the question lacks explanations and, besides, the title "No refresh" on the site has a lot of subject on it. Of course you can solve the situation without using ajax to solve the problem, but "without refresh", the solution I would give would be yes using AJAX. If the problem is another, then the title and description of the question must be another.
– Wallace Maxters
Clayton, you are wearing
session_start()
?– Wallace Maxters