>What's the best way to implement functions like 'add to basket' or 'add to >wishlist' and so on. > >I mean: you are on a page with detail information about a product. If the >user clicks the link for 'add to basket' I have to perform a piece of >script and then go back to the detail page of the given product. But >clicking on this link leads me away form the page... > >I was thinking of using $HTTP_REFERER i the "ad_to_basket.php" page in >order to retrieve the last url, but now I don't know how to go back to this >detailpage, is there a php command for this, or is my approach totally wrong??
------------- sample.php ------------------------ <?php require 'basket.inc'; ?> Display rest of page here. <A HREF=<?=$PHP_SELF?>?item_id=42>Item # 42</A> Display items already in cart: <?php $query = "select item_id from basket where user_id = '$user_id'"; $basket = mysql_query($query) or error_log(mysql_error()); while (list($item_id) = mysql_fetch_row($basket)){ echo "$item_id<BR>\n"; } ?> ---------------------------------------------------- ------------- basket.inc ------------------- <?php session_start(); $user_id = session_id(); if (isset($item_id)){ $query = "insert into basket (user_id, item_id) values('$user_id', $item_id)"; mysql_query($query) or error_log(mysql_error()); } ?> ------------------------------------------- You'll want to complicate this horribly with a "quantity" so you'll need to check if they have any or not, and then do an "insert" if they don't and an "update quantity = quantity + 1" if they do, and then validating data, and so on, but that's really all there is to a shopping cart at its most simplistic. What most people mean when they say "shopping cart" these days is "shopping cart" and "shipping charges" and "catalog system" and "pricing structures" and "secure checkout" and... -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php