wap3
11-18-2002, 12:13 PM
Hello
I am trying to learn php etc and so setup a database on my site. I have managed to set-up the database and generate all the relevant pages. I am however struggling on making a shopping cart. I have tried looking at some tutorials but can't work it out. I have a php generated page which lists items in the database and for each of those item, they all have a button with a unique ahref tag. e.g add_to_basket.php?Item_id=56
Now if i click on that button for example how can I get it to store that in a session for later use. This is all I have to start this off. I would appreciate some help with this. Some pointers etc or maybe a little bit of code.
<?
include ('cart_fs_library.php');
// The shopping cart needs sessions, so start one
session_start();
if(!session_is_registered("cart"))
{
$cart = array();
session_register("cart");
$items = 0;
session_register("items");
}
if($cart[$Item_id])
$cart[$Item_id]++;
else
$cart[$Item_id] = 1;
if($cart&&array_count_values($cart))
display_cart($cart);
else
{
echo "<p>There are no items in your cart";
echo "<hr>";
}
This is abit of a mock-up which I have kind of gathered from various places. Is this any good ??
Any help appreciated
:thumbsup:
I am trying to learn php etc and so setup a database on my site. I have managed to set-up the database and generate all the relevant pages. I am however struggling on making a shopping cart. I have tried looking at some tutorials but can't work it out. I have a php generated page which lists items in the database and for each of those item, they all have a button with a unique ahref tag. e.g add_to_basket.php?Item_id=56
Now if i click on that button for example how can I get it to store that in a session for later use. This is all I have to start this off. I would appreciate some help with this. Some pointers etc or maybe a little bit of code.
<?
include ('cart_fs_library.php');
// The shopping cart needs sessions, so start one
session_start();
if(!session_is_registered("cart"))
{
$cart = array();
session_register("cart");
$items = 0;
session_register("items");
}
if($cart[$Item_id])
$cart[$Item_id]++;
else
$cart[$Item_id] = 1;
if($cart&&array_count_values($cart))
display_cart($cart);
else
{
echo "<p>There are no items in your cart";
echo "<hr>";
}
This is abit of a mock-up which I have kind of gathered from various places. Is this any good ??
Any help appreciated
:thumbsup: