I have a shopping cart which uses PHP. When a person adds something to their cart, the relevant code is done at the top of cart.php, meaning they have to leave the product page as they add something to cart, and end up having to press the back button if they want to do more.
How do I execute PHP/SQL code when a user clicks "add to cart", but without redirecting them to a new page? I think Jquery/JSON is needed here, but I don't know the first thing about that. Something like the below:
//product page
<input type="button" value="3"/>
//when the button is clicked, do some SQL/PHP based on the value on the same page
Originally, I had:
//product page
<form action="./cart.php" method="post">
//some code for user to select whats to be submitted
<input type="submit"/>
</form>
...
//cart page
//some logic relevant to taking value from product page and adding to cart
//then display cart contents
The problem is that it takes them to a new page when I'm positive the logic can be done on the same page onclick of button.