I am hoping that someone out there can save me some hair and frustration with this problem

I am creating a custom shopping cart application for a client using Perl and MySQL to keep track of user sessions and shopping cart information, the script checks to see if a cart exists for the user when they log in, and if it does it checks to see if the cart is expired. The problem I am having is that when the script checks for the cart expiration on adding an item to the cart, the SQL result comes back empty even if the cart exists and is not expired.

to be a little clearer -

The cart script checks to see if the user is logged in - if the user is not logged in, they are redirected to the login page and asked to log in. The log in processing script checks to see if the user exists ( duh ) and then if everything is ok, it checks for the existance of a shopping cart for that user. If a cart exists in the database for the user, the script moves on to check and see if the cart is expired or not - if the cart is expired, then a new cart is generated and the old cart is discarded. This works fine when logging in, but when continuing on to adding an item to the cart, the exact same code block returns that the cart is expired even
when it is a brand new cart.

I am using custom modules to save on written code

<code snippet: ehgModule.pm >
....................misc code .........................>
sub cartExists { #check to see if a cart exists for this user
 my $self = shift;
my $ws = new commonModule; # points to commonModule.pm which is 'used' in the header of this module for common code my $dbh = $ws->DBC; # connects to the mysql database and returns the connection handler
 my $username = shift;
my $sql = qq{ SELECT fldcartid, fldexpires FROM ehgStoreCarts WHERE fldusername='$uname' };
 my $sth = $dbh->prepare($sql);
 $sth->execute;
 if ($sth->rows == 0) { # no cart exists
   $sth->finish;
   $dbh->disconnect;
   return 0;
 }
 my ($cart_id, $cart_exp) = $sth->fetchrow();
 $sth->finish;
 $dbh->disconnect;
 return $cart_id;
}

sub cartExpired {  # checks to see if cart is expired
 my $self = shift;
 my $cart_id = shift;
 my $ws = new commonModule;
 my $dbh = $ws->DBC;
my $sql = qq{ SELECT fldexpires FROM ehgStoreCarts WHERE fldcartid='$cart_id' };
 my $sth = $dbh->prepare($sql);
 $sth->execute;
my $expires = $sth->fetchrow(); # only one record should exist for each cart so this works
 $sth->finish;
 $dbh->disconnect;
 my $now = time;
 if ($now > $expires) {
    return 1;
 } else {
    return 0;
 }
}
</snippet>
<code snippet : login.cgi >
.............misc info ...............>
my $user = new ehgModule;   # new instance of the cart common code module
................ blah blah ................>
my $cart_info = $user->cartExists($user_name);
if (!$cart_info) { # no cart in database
 $shopcartid = $user->genCartID($user_name);
 $is_newcart = 1;
} else {
 $shopcartid = $cart_info;
 $is_newcart = 0;
}
if ($user->cartExpired($shopcartid) == 1) {
 #renew cart code...........
}
</snippet>
this code works fine - if the cart exists and is not expired, it continues on to redirecting to the main add script

when I use the exact same methods in the add to cart functions it returns that the cart is expired - I debugged the SQL results and it turns out that the SQL query returns nothing -- even just a minute after the cart is created.

any help would be appreciated

____ • The WDVL Discussion List from WDVL.COM • ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or
use the web interface http://e-newsletters.internet.com/discussionlists.html/
      Send Your Posts To: [email protected]
To change subscription settings, add a password or view the web interface:
http://intm-dl.sparklist.com/read/?forum=wdvltalk

________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]
To unsubscribe via postal mail, please contact us at:
Jupitermedia Corp.
Attn: Discussion List Management
475 Park Avenue South
New York, NY 10016

Please include the email address which you have been contacted with.

Reply via email to