PHP Script for updating Shopping Cart
We update the session variable $_SESSION['cart'] using PHP script. This page ( add.php ) will receive product_id and quantity against each product and update the cart.
add.php The backend PHP scriptThe PHP code inside add.php first receive the data Product id (p_id) and quantity ( qty ) from front end script.
Data validation is done by setting Flags
If the validation is cleared then Session status is checked, if it is not there then new session is created.
If the product id is already there then the product is removed first.
If quantity is not equal to zero then add the product with new quantity.
We need to find out the total number of products in the cart after all above transactions are completed. This data we will send to front end script as we have to update the data at top right side of the page.
At the end we will send the JSON output to our front end script.
Subscribe to our YouTube Channel here
This article is written by plus2net.com team. https://www.plus2net.com