Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-03-2007, 02:32 PM   #1 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
Shopping Cart with Sessions

I am trying to create a shopping cart with sessions. I want the final session to end up as something like 'number,number,numer' with the numbers being various product ids. I have the following codes on the pages but the view-cart.php page shows nothing.

product.php
PHP Code:
echo("<form action=\"add-cart.php\" method=\"post\">\n");
echo(
"<input type=\"hidden\" name=\"id\" value=\"".$id."\">\n");
echo(
"<input type=\"submit\" value=\"Add to Cart\">\n");
echo(
"</form>\n"); 
add-cart.php
PHP Code:
$prodid $_POST['id'];
$cart $_SESSION['cart'];
if (
$cart) {
    
$_SESSION['cart'] .= ",".$prodid;
} else {
    
session_register('cart');
    
$_SESSION['cart'] == $prodid;

view-cart.php
PHP Code:
echo($_SESSION['cart']); 
session_start(); is included as default at the very top of all pages.

The problem is the code on view-cart.php echoes nothing

please help!

Last edited by markster; 02-03-2007 at 02:33 PM. Reason: Problem with copy/pasting codes
markster is offline   Reply With Quote
Old 02-03-2007, 03:38 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Code:
...
} else {
    session_register('cart');
    $_SESSION['cart'] == $prodid;
}
Shouldn't this be
Code:
...
} else {
    session_register('cart');
    $_SESSION['cart'] = $prodid;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 02-03-2007, 03:59 PM   #3 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 745
DJMaze is on a distinguished road
I see someone mis-interpreted session_register().
Please read http://php.net/session_register
Quote:
Register one or more global variables with the current session
So, where is $cart?
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beware the multiple option shopping cart . . . metazai PHP 9 08-31-2005 09:05 AM
Struts santhini Java 1 05-16-2005 09:03 AM
shopping cart systems sde PHP 5 07-08-2003 10:03 PM
shopping carts / account interfaces... sde PHP 4 07-10-2002 01:01 PM


All times are GMT -8. The time now is 08:46 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting