Current location: Hot Scripts Forums » Programming Languages » PHP » MySQL & PHP Shopping cart question


MySQL & PHP Shopping cart question

Reply
  #1 (permalink)  
Old 03-22-08, 09:55 AM
mcrob mcrob is offline
Coding Addict
 
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
MySQL & PHP Shopping cart question

Hey there I have a question...

I was thinking of having this. If a user is not registered on the website, if this user adds a product to the cart, he or she has to be logged in to use this feature. I also found a website that does the same.

http://www.traxsource.com

Do you believe this could be a problem or no?
Reply With Quote
  #2 (permalink)  
Old 03-22-08, 10:00 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Not quite sure what you are asking here. Do you mean that you think having a shopping cart that people can use whilst not logged in is a problem? If all items are stored in session variables, I dont think it is all that important, because you can force the user to log in when they have finished their shopping and go to checkout. Then they sign in and all their cart is saved still
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #3 (permalink)  
Old 03-22-08, 10:03 AM
mcrob mcrob is offline
Coding Addict
 
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
I was thinking if the user is not logged in, they won't be able to save the products to the shopping cart....
Reply With Quote
  #4 (permalink)  
Old 03-22-08, 10:06 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
They wont be able to save the shopping cart no, but it will be held by the session until it expires. Once the user has logged in, you could save the cart, but you cant really without their username
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #5 (permalink)  
Old 04-14-08, 02:47 PM
mcrob mcrob is offline
Coding Addict
 
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
This is what I was thinking.....

I went on a couple of shopping cart websites and I learned what a lot of them to do is
when a customer adds a product to there shopping cart, because a sessionID was
made for them, it creates a cookies and stores the given sessionID in the cookies and the products that they add to there shopping cart gets stored in the database. So when the customer closes the browser and comes back let's say in 2 days (plus it all depends on when the cookie expires too) and the products are still in there shopping cart since it loaded the sessionID from there computer and in the database there sessionID it stored there which pulls up all the products they saved from before. Now that I understand this what if the customer decides not to come back? What kind of script could I use that would delete there saved product from the database after a certain time?
Reply With Quote
  #6 (permalink)  
Old 04-14-08, 02:51 PM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
I wouldn't bother with storing the shopping cart data for non-logged in users in the database. Store it in a session array. Thats the best way, but for logged in users it is best to store in the database.
__________________
Can you think outside the box but remain inside the box?
Reply With Quote
  #7 (permalink)  
Old 04-14-08, 03:24 PM
mcrob mcrob is offline
Coding Addict
 
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
Actually just made an edit on this post here. I opened this shopping cart tutorial and I noticed this the programmer made a function to delete the abandoned cart that has
been one day old or more.

PHP Code:

function deleteAbandonedCart()


{

    
$yesterday date('Y-m-d H:i:s'mktime(0,0,0date('m'), date('d') - 1date('Y')));

    
$sql "DELETE FROM tbl_cart

            WHERE ct_date < '
$yesterday'";

    
dbQuery($sql);        


I kind of need a better understanding of how this works. How can I make it so its expires in 5 days instead of 1 day?

Last edited by mcrob; 04-14-08 at 03:46 PM.
Reply With Quote
  #8 (permalink)  
Old 04-14-08, 03:50 PM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:



function deleteAbandonedCart()

{

    
$yesterday date('Y-m-d H:i:s'mktime(0,0,0date('m'), date('d') - 5date('Y')));

    
$sql "DELETE FROM tbl_cart

            WHERE ct_date < '
$yesterday'";

    
dbQuery($sql);        


but I still say using an session array would be best. Because if you have the cookie set to five days it will expire all the same and also the sessions stored on the server gets deleted after a certain amount of time.
__________________
Can you think outside the box but remain inside the box?
Reply With Quote
  #9 (permalink)  
Old 04-14-08, 04:01 PM
mcrob mcrob is offline
Coding Addict
 
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
ok.. are there any examples of using an session array in a php shopping cart?
Reply With Quote
  #10 (permalink)  
Old 04-14-08, 04:07 PM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
__________________
Can you think outside the box but remain inside the box?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shopping cart script that doesn't look like another shopping cart script deanloh Script Requests 8 05-10-09 03:56 PM
In-depth question about PHP (shopping cart) droomagon PHP 1 10-05-06 03:19 PM
WEB HOSTING - $4.99/MONTH For 1GB HD & 25GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 0 10-20-05 07:26 AM
PHP to MySQL script question...(using a field to update info in MySQL) DisneyFan25863 PHP 4 11-02-03 03:31 AM
MySQL with PHP question. HELP for a newbie kenfused PHP 3 08-02-03 12:53 AM


All times are GMT -5. The time now is 07:39 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.