hallo all..i got some problem in using the session in ASP. i hope u all can guide me in detail.
i have a form, inside got 3 drop down and one text box. and got one Add button. wat i wan to do is:
after fill in the value for this form, then click the add button and it will display the value in the 2nd page. the data hasnt insert into the database yet. then when user click on continue button in the 2nd page, it can add another new record , etc...until the user click on the FINISH button on the 2nd page, then all the records will insert into DB. it is something similar to the shopping cart ...but i duno how is work?

can someone plz teach me how to keep the record from the form as session? how is it work ..plz help....i need some guide on how to start the coding . im quite new in asp..so i got some problem on how to code it..
thank you

Dani AI

Generated

A short, practical pattern for the “collect items in memory until FINISH” workflow in classic ASP (builds on ideas from and ). Keep form posts small: each Add submits form values to a handler that appends a single line for that item into a Session variable. A review page reads Session, shows items, and offers Continue (back to form) or Finish (iterate Session and insert into DB). Clear the Session when done.

Example: append one item (use a rare char as record separator).

<%
' add.asp
Dim item, sep
sep = Chr(31)
item = Request.Form("prod") & "|" & Request.Form("opt1") & "|" & Request.Form("qty")
If Len(Session("Cart") & "") = 0 Then
  Session("Cart") = item
Else
  Session("Cart") = Session("Cart") & sep & item
End If
Response.Redirect "cart.asp"
%>

Example: read Session and render the review list.

<%
cart = Session("Cart") & ""
If Len(cart) > 0 Then
  items = Split(cart, Chr(31))
  For i = 0 To UBound(items)
    fields = Split(items(i), "|")
    Response.Write Server.HTMLEncode(fields(0)) & " x " & Server.HTMLEncode(fields(2)) & "<br/>"
  Next
End If
%>

Example: on Finish, loop items and insert with parameterized ADO commands (prevents SQL injection), then clear Session.

<%
' finish.asp (pseudo)
conn.Open connStr
items = Split(Session("Cart") & "", Chr(31))
For i = 0 To UBound(items)
  fields = Split(items(i), "|")
  ' use ADODB.Command with parameters to insert fields(0/1/2)
Next
Session("Cart") = ""
conn.Close
%>

Key tips: validate all inputs server-side; use parameterized commands for DB inserts; be aware Session uses server memory and depends on cookies (users blocking cookies will lose Session); Session.Timeout defaults to 20 minutes; for high traffic or persistent carts prefer a temporary DB table keyed to a token instead of large Session objects. To debug, Response.Write the raw Session("Cart") and test in different browsers to confirm session isolation.

Recommended Answers

All 3 Replies

hallo all..i got some problem in using the session in ASP. i hope u all can guide me in detail.
i have a form, inside got 3 drop down and one text box. and got one Add button. wat i wan to do is:
after fill in the value for this form, then click the add button and it will display the value in the 2nd page. the data hasnt insert into the database yet. then when user click on continue button in the 2nd page, it can add another new record , etc...until the user click on the FINISH button on the 2nd page, then all the records will insert into DB. it is something similar to the shopping cart ...but i duno how is work?

can someone plz teach me how to keep the record from the form as session? how is it work ..plz help....i need some guide on how to start the coding . im quite new in asp..so i got some problem on how to code it..
thank you

Hi,
There are 2 ways either u pass the values through querystring or u can use the session variables, Let u can try any of these as im also new to ASP.....

--karthik

karthik is correct, the easiest way (least secure method) would be to use request.querystring to pass the variables between pages.

Passing querystrings is simple. Each <input> is given a name and the value of the <input> is the value shown in the querystring. That name/value pair is what you see in the querystring.

For instance:

<input type="text" name="txt1">THIS TEXT</input>

...will produce this in the address bar of the page listed in your <form> tag:

/somepage.asp?txt1=THIS+TEXT&submit=Add

You can also use Session cookies, which is a bit more complex. If you'd really like to learn about Sessions, I suggest reading this: http://www.w3schools.com/asp/asp_ref_session.asp

hi all..thanx for all the guidance and response...i have solve it..thank you very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.