newbie - sessions

M

monki

I am trying to build a simple shopping cart

I am trying to store the contents of the cart in the session.

I have 2 questions

1) I am trying to see if the product is exists in the session, if it is
then rather than add the product again I want to add to the quantity of the
existing product

The code I am using is
_________________________________
strProd=request.form("ProdId")
strQty=request.form("Qty")

If Session(strProd)="" Then
Session(strProd) = strQty
Else
strOldQty=Session(strProd)
strNewQty=(strQty+strOldQty)

Session(strProd) = strNewQty
End if
_________________________________

Rather than adding the quantities the code puts the second qty after the
first I.e. 11 rather than 2

How do I get the addition to work. I have tried several different methods
but always get the same results?

2) Is this the best way of building a simple cart. I have thought about
just adding the cart into a database however I cant work out how to delete
the records if the session times out or is abandoned. I have looked at
Session_OnEnd but can not find any code examples of how this is used

Thanks in advance

J
 
E

Evertjan.

monki wrote on 29 mei 2004 in microsoft.public.inetserver.asp.general:
Rather than adding the quantities the code puts the second qty after
the first I.e. 11 rather than 2

How do I get the addition to work. I have tried several different
methods but always get the same results?

We are talking vbscript:

session("...") always returns a string

string + string concatenates the strings just like string & string

response.write "3" + "4" ' shows 34

change the strigns to numberic and they are added

response.write 1*"3" + 1*"4" ' shows 7
2) Is this the best way of building a simple cart. I have thought
about just adding the cart into a database however I cant work out how
to delete the records if the session times out or is abandoned. I have
looked at Session_OnEnd but can not find any code examples of how this
is used

do not use Session_OnEnd, it is unreliable, it will not fire if the
server crashes. Do not add a final record till the final acknowledgement.

I think you still have much to learn about ASP and vbscript, if you do
not know when a number is realy a string and a reliable cart is probably
still out of your reach.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top