php - How do I display a summary of items in a cart from a $_SESSION onto another page -


i need cart page show summary "line item" view of vending machines purchased on vend page $_session['cart']

here code allows me add multiple items cart: (vend page)

 session_start();   //check if $_session['cart] exists  if (!isset($_session['cart'])) {   //initiate cart empty array           $_session['cart'] = [];  }   if (isset($_post['add'])) {   //add product id session cart  $_session['cart'][$_post['add']] =1;  }   else if (isset($_post['remove'])) {      //remove product id session cart     unset($_session['cart'][$_post['remove']]); } 

i need way display items "add cart" on vend page" display in list onto page "cart page". ive made image show how should displayed: here

in cart page add -

session_start(); if (isset($_session['cart'])) { foreach ($_session['cart'] $name => $price){     echo $name . " - " . $price;  } }else{ // optional(if cart empty redirect page)   header("location:products.php"); } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -