article

How to destroy a Shopping Cart

Email
Submitted on: 1/5/2015 2:32:00 PM
By: Lewis E. Moten III (from psc cd)  
Level: Intermediate
User Rating: By 5 Users
Compatibility: ASP (Active Server Pages)
Views: 661
 
     I often get questions on how to deal with shopping cart data stored within the database that is no longer needed after the user has logged off. The answer is simple and deals with some database calls in the Global.ASA.

 
				

As you user adds an item into there shopping cart, you should create a field that also holds the value of the SessionID (Session.SessionID). This ID is unique to all of your "current" visitors. When a users session ends, you can "clean up" your database by deleting all of the records relating to that session ID. Here is a brief run-down on the SQL you would execute in your Global.ASA file.

<SCRIPT language="vbScript" runat="Server">
Sub Session_onStart()
lStrSQL = "DELETE FROM ShoppingCartItems WHERE SessionID = " & Session.SessionID
End Sub
' this is the main one you want - the others just help make
' sure records get deleted if they are not needed.
Sub Session_onEnd()
lStrSQL = "DELETE FROM ShoppingCartItems WHERE SessionID = " & Session.SessionID
End Sub
Sub Application_onStart()
lStrSQL = "DELETE FROM ShoppingCartItems"
End Sub
Sub Application_onEnd()
lStrSQL = "DELETE FROM ShoppingCartItems"
End Sub
SCRIPT>


Other 63 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.