shopping cart

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

shopping cart

Post by shiznatix »

I am trying to code a small shopping cart that when you click checkout it passes everything to paypal. Questions -

A: How should I save the shopping cart infomation for each person? Is doing it through cookies bad? I can't have the user register with me so using a db with stored username and password wont go. Any sugestions on that will be very helpful.

B: Is there any way that anyone knows about that when the person pays their cookies will be deleted as to empty their shopping cart on my server?

Thanks. (and yes I have researched this stuff but have found no answers :( )
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. sessions
  2. if you have the option to use a thank you type page, or any page that ends on your server, you can erase the session then..
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

I have worked with Paypal and Authorize.Net and that problem occured with me too. See they have a pre-defined var names that you pass it for the transaction to occur. If you pass it any other var e.g. user_registration_no along with its value it will return that same key-value pair in its response :!: So damn simple ;)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

awesome ill look into it!

ps what happened to all the avatars?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

ok problem, im coding the shopping cart with sessions. this is my code so far

Code: Select all

$_SESSIONї'products'] = $_SESSIONї'products'].'*'.$item_name.'*';
$_SESSIONї'total'] = $_SESSIONї'total']+$amount;

$pro = explode('*', $_SESSIONї'products']);
$count = count($pro);

$query = mysql_query("SELECT * FROM items ORDER BY itemid DESC");
while($item = mysql_fetch_assoc($query)){
	for($i=0; $i<$count; $i++)&#123;
		if ($pro&#1111;$i] == $item&#1111;'name'])&#123;
			$itm = $item&#1111;'name'];
			$_SESSION&#1111;$itm] = $_SESSION&#1111;"$itm"]+1;
		&#125;
	&#125;
&#125;

while($item = mysql_fetch_assoc($query))&#123;
$itm = $item&#1111;'name'];

	foreach($_SESSION&#1111;$itm] as $itmc => $amt)&#123;
	echo '<br>______________<br>';
	echo 'You have '.$amt.' of '.$itmc.'<br>';
	echo '<br>______________<br>';
	&#125;
&#125;
	
echo 'Your total is'.$_SESSION&#1111;'total'];
where i think im having the trouble is in setting the session item name with its value. its suposed to for each item you added to your cart it checkes the amount that you want for that item but doing a $_SESSION[$itm]; to make the session thing based on the item name is definatly not working i dont think. any sugestions?...or is this just complete garbage and my only real option is suicide?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

scratch that, that sucks i know.

but! i have a db that stores the cartID as your session id and there will be multiple rows with your cartID and each has its own itemID. I need to take all of the itemID's and turn them into a array so it will look like
array(123, 542, 67) each number being a seperate itemID where your cartID equals your session id. I dont know the sql to do this. Help?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Not SQL but a little of PHP+MySQL ;)

Code: Select all

$result = mysql_query("SELECT itemID FROM cartDB WHERE cartID = '".session_id()."'") or die("Damn! You can't even write SQL correctly!<br>".MySQL_Error()); //;)
while(items&#1111;] = mysql_fetch_row($result));
That should do it!
Post Reply