Page 1 of 1
Simplified Shopping cart - why won't this work?
Posted: Wed Jul 21, 2010 11:35 am
by simonmlewis
Code: Select all
session_start();
$idinc = ($idinc + 1);
$buyid=('buyid'.$idinc);
if(isset($_REQUEST['buyid']))
{
$buyid = $_REQUEST['buyid'];
$_SESSION['buyid']=$buyid;
} else { $buyid=$_SESSION['buyid'];
}
echo "$buyid";
<a href='index.php?page=product&product=$row->id&s=$row->subid&c=$row->catid&cname=$row->catname&sname=$row->subname&menu=sub&buyid=$row->id'>Buy Now</a>
I am trying to post the ID of a product to an auto-incremental 'buyid' in a global variable in the session.
This isn't storing anything. Maybe I am going about this the wrong way. The idea being that you can store all the product ids you want in your "cart", and then you extract it from the database later on, based on the "buyid" in the Cart page.
Can anyone help me please?
Re: Simplified Shopping cart - why won't this work?
Posted: Wed Jul 21, 2010 11:59 am
by Alex-V
You need to store last buyid in your db. Session are separate for each user you can't increase a value that is not set.
Re: Simplified Shopping cart - why won't this work?
Posted: Wed Jul 21, 2010 12:36 pm
by simonmlewis
I don't understand why you can't store a session variable in this way.
But would you then say that I ought to have a 'cartdb' and a 'orderdb' to store the shopping cart, and then the ORDERS separately?
Re: Simplified Shopping cart - why won't this work?
Posted: Wed Jul 21, 2010 12:40 pm
by Alex-V
You don't need 2 db's to store that data. Just two tables. You can assign one id to one user via session but then next user will get the same id because your script doesn't know what is the last it (the one that last user got). I hope you understand me
