Jump to content

add to cart


steveh62

Recommended Posts

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.