steveh62 Posted February 12, 2009 Share Posted February 12, 2009 I have a number of input types like the following retreiving data values from php <form name"" action=""> <input type="hidden" name="pid" value="<? $pid; ?> /> <input type="submit" value="add to cart"/> </form> question is: How can I add to cart the contents of a selected item and then add another [different] item to cart and list them so they are unique to the cart each time an item is added. Link to comment https://forums.phpfreaks.com/topic/144931-add-to-cart/ Share on other sites More sharing options...
gevans Posted February 12, 2009 Share Posted February 12, 2009 That's a big question with very little code. Have you built your own cart system, or are you using software? If you're doing it yourself and can't figure out a mediumish size step like this I'd recommend looking into some free software. I have the feeling what you need to do is add an array to your cart's session... that is if you're using a session for this!? Link to comment https://forums.phpfreaks.com/topic/144931-add-to-cart/#findComment-760686 Share on other sites More sharing options...
steveh62 Posted February 13, 2009 Author Share Posted February 13, 2009 thought as much...a session array that is then travel that array to pull the relavent data out on a <tr><td>row</td></tr> at the moment I am passing all the data to another php processor page which collects and can echo that data....I just needed it in a way that looks and acts like a cart. Link to comment https://forums.phpfreaks.com/topic/144931-add-to-cart/#findComment-761120 Share on other sites More sharing options...
gevans Posted February 13, 2009 Share Posted February 13, 2009 On the processor page why not do something like this. <?php session_start(); $foo = $_POST['pid']; $_SESSION['cart_items'][] = $foo; That way every item will be added into cart_items and be echoed as follows; <?php session_start(); foreach($_SESSION['cart_items'] as $pid){ echo $pid; } That will echo out your pid, obviously you neeed to use that to find your products from your db Link to comment https://forums.phpfreaks.com/topic/144931-add-to-cart/#findComment-761185 Share on other sites More sharing options...
steveh62 Posted February 13, 2009 Author Share Posted February 13, 2009 thanks for that...but I have now opted to send the data items to mysql to handle all of the cart_items including a unique user session id. Basically, I send all of the data to a table and when inserted it sends the user to viewcart which checks the current session_id against one created when adding item/s to the cart and shows the user/buyer what they have ordered. additonally there is date added to an item added to the cart, this will be used to 'flush' the table after an hour or so...so as to not bog the table with unused data. I just thought I could have used a better way for a user to track their goods when adding them to cart...OH well Link to comment https://forums.phpfreaks.com/topic/144931-add-to-cart/#findComment-761194 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.