Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. session_start();
  2.  
  3. //Check if $_SESSION['cart] exists
  4. if (!isset($_SESSION['cart'])) {
  5.  
  6. //initiate cart as empty array
  7. $_SESSION['cart'] = [];
  8. }
  9.  
  10. if (isset($_POST['add'])) {
  11.  
  12. //add product id to session cart
  13. $_SESSION['cart'][$_POST['add']] =1;
  14. }
  15.  
  16. else if (isset($_POST['remove'])) {
  17.  
  18. //remove product id from session cart
  19. unset($_SESSION['cart'][$_POST['remove']]);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement