Creating a shopping cart using PHP cookies

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
leo76uk
Forum Newbie
Posts: 1
Joined: Sun Jul 18, 2010 5:17 pm

Creating a shopping cart using PHP cookies

Post by leo76uk »

Hi everyone,
I am creating a shopping cart using cookies. The item is post method form which can be $cart = $_REQUEST['item']. I am trying to create an array of requested items using
<?php
if ($cart) {
$cart .= ',' .$_REQUEST['item'];
} else {
$cart = $_REQUEST['item'];
}
setcookie( "product", $cart,time()+86400);
?>
But not able to retrieve data using the following so the get items from the database.
<?php
if ($cart) {
$items = explode(',',$cart);
foreach ($items as $item) {
echo $item;
}
}
?>
Can anybody give me the solutions?
Post Reply