juanc Posted June 24, 2007 Share Posted June 24, 2007 Hi I'm trying to make a basic shopping based on the idea that an item selected get's pushed into an array and then that array get's saved into a session variable. If I did this.. <?php $shop = array("plasma TV","DVD recorder","mountain bike","coffee maker"); $_SESSION['cart'] = $shop; ?> I'm able to access $_SESSION['cart'] with all the array values on a completely different page no problem. However I want to have a page listing items for sale then each time a customer clicks on an item that get's added to $_SESSION['cart'] and of course each time you are able to see the latest snapshot of the cart. I wrote this myself......... <?php // 1st page <a href=cart.php?id=1>Computer</a><br /> <a href=cart.php?id=2>CD collection</a> // then on cart.php if(!in_array($_GET['id'],$_SESSION['cart'])) { $items_in_cart[] = $_SESSION['cart']; $new_entry[] = $_GET['id']; $all_the_items = array_merge($items_in_cart,$new_entry); $all_the_items = $_SESSION['cart']; } ?> what basically happens is if I do a foreach loop on $_SESSION['cart'] it's fine...I see all the original items (Plasma TV etc) plus the new one selected....however if I were to leave the page and then re visit I only see the original items in the original $shop array ...and not the latest one to be selected. Hope someone can help. Link to comment https://forums.phpfreaks.com/topic/56950-basic-shopping-cart-problem/ Share on other sites More sharing options...
chigley Posted June 24, 2007 Share Posted June 24, 2007 You're forgetting session_start() at the top of each page. Link to comment https://forums.phpfreaks.com/topic/56950-basic-shopping-cart-problem/#findComment-281305 Share on other sites More sharing options...
juanc Posted June 24, 2007 Author Share Posted June 24, 2007 chigley I've done that......it's just I haven't bothered entering that much detail onto what I've posted here... To sum my question.........how do you keep inserting values into an array that stays persistent across different pages? Link to comment https://forums.phpfreaks.com/topic/56950-basic-shopping-cart-problem/#findComment-281330 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.