473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Session Variable for Shopping Cart

I'm losing information from my Session when I change pages or start the same
page over again. I simplified the code so the example is really clear. The
sample code that follows is supposed to generate a random number and put it
into an Array and store it in the Session variable and then when it runs the
next time, generate another random number and display the entire Array
contents, by pulling the information out of the Session. I'd greatly
appreciate someone with fresh eyes taking a look at this code. Thanks.

<%@ LANGUAGE="VBSCRIPT" %>

<%
if Request.Form("clear") = "true" then
Session.Contents.Remove("ShoppingCart")
Session("ItemCount") = 0
clearcart = ""
end if

dim cart(999,9)

Randomize Timer
r1 = Rnd
r1 = r1 * 1000000
intOrderID = 1000000 + Int (r1)

intItemCount = Session("ItemCount")

if intItemCount = 0 then
intItemCount = 1
Session("ItemCount") = intItemCount
else
intItemCount = intItemCount + 1
Session("ItemCount") = intItemCount
end if

Session("ItemCount") = intItemCount

cart(intItemCount,1)=intOrderID
Session("ShoppingCart")=cart

xcart=Session("ShoppingCart")

for x = 1 to intItemCount
response.write x & " " & xcart(x,1) & "<br>"
next

%>
<form action="array.asp" method="post">
<input type="hidden" name="clear" value="true">
<input type="Submit" name="Submit" value="Clear Shopping Cart">
</form>
<form action="array.asp" method="post">
<input type="hidden" name="clear" value="false">
<input type="Submit" name="Submit" value="Reload">
</form>
Apr 12 '06 #1
5 3150

"TRB_NV" <TR****@hotmail.com> wrote in message
news:O0*************@TK2MSFTNGP04.phx.gbl...
I'm losing information from my Session when I change pages or start the same page over again. I simplified the code so the example is really clear. The sample code that follows is supposed to generate a random number and put it into an Array and store it in the Session variable and then when it runs the next time, generate another random number and display the entire Array
contents, by pulling the information out of the Session. I'd greatly
appreciate someone with fresh eyes taking a look at this code. Thanks.

<%@ LANGUAGE="VBSCRIPT" %>

<%
if Request.Form("clear") = "true" then
Session.Contents.Remove("ShoppingCart")
Session("ItemCount") = 0
clearcart = ""
end if

dim cart(999,9)

Randomize Timer
r1 = Rnd
r1 = r1 * 1000000
intOrderID = 1000000 + Int (r1)

intItemCount = Session("ItemCount")

if intItemCount = 0 then
intItemCount = 1
Session("ItemCount") = intItemCount
else
intItemCount = intItemCount + 1
Session("ItemCount") = intItemCount
end if

Session("ItemCount") = intItemCount

cart(intItemCount,1)=intOrderID
Session("ShoppingCart")=cart

xcart=Session("ShoppingCart")

for x = 1 to intItemCount
response.write x & " " & xcart(x,1) & "<br>"
next

%>
<form action="array.asp" method="post">
<input type="hidden" name="clear" value="true">
<input type="Submit" name="Submit" value="Clear Shopping Cart">
</form>
<form action="array.asp" method="post">
<input type="hidden" name="clear" value="false">
<input type="Submit" name="Submit" value="Reload">
</form>

You have a hidden field whose value is always true. Hence the code at the
top of your page that resets everything always runs.

Apr 12 '06 #2
Remarked out the part about clearing the Session contents, but I'm still not
getting the data from the Array I stored in it:

'if Request.Form("clear") = "true" then
' Session.Contents.Remove("ShoppingCart")
' Session("ItemCount") = 0
' clearcart = ""
'end if

From everything I've read, it appears that I can store an Array in a Session
variable and recall it. Some how it's not working properly.
Apr 12 '06 #3

"TRB_NV" <TR****@hotmail.com> wrote in message
news:%2*****************@TK2MSFTNGP02.phx.gbl...
Remarked out the part about clearing the Session contents, but I'm still not getting the data from the Array I stored in it:

'if Request.Form("clear") = "true" then
' Session.Contents.Remove("ShoppingCart")
' Session("ItemCount") = 0
' clearcart = ""
'end if

From everything I've read, it appears that I can store an Array in a Session variable and recall it. Some how it's not working properly.


You've got these lines in your code too

Session("ShoppingCart")=cart

xcart=Session("ShoppingCart")

Are you saying xcart does contain the same data as cart?

What if you change this to:-

xcart = cart does it still fail?


Apr 12 '06 #4

TRB_NV wrote:
I'm losing information from my Session when I change pages or start the same
page over again. I simplified the code so the example is really clear. The
sample code that follows is supposed to generate a random number and put it
into an Array and store it in the Session variable and then when it runs the
next time, generate another random number and display the entire Array
contents, by pulling the information out of the Session. I'd greatly
appreciate someone with fresh eyes taking a look at this code. Thanks.

<%@ LANGUAGE="VBSCRIPT" %>

<%
if Request.Form("clear") = "true" then
Session.Contents.Remove("ShoppingCart")
Session("ItemCount") = 0
clearcart = ""
end if

dim cart(999,9)

Randomize Timer
r1 = Rnd
r1 = r1 * 1000000
intOrderID = 1000000 + Int (r1)

intItemCount = Session("ItemCount")

if intItemCount = 0 then
intItemCount = 1
Session("ItemCount") = intItemCount
else
intItemCount = intItemCount + 1
Session("ItemCount") = intItemCount
end if

Session("ItemCount") = intItemCount

cart(intItemCount,1)=intOrderID
Session("ShoppingCart")=cart

xcart=Session("ShoppingCart")

for x = 1 to intItemCount
response.write x & " " & xcart(x,1) & "<br>"
next

%>
<form action="array.asp" method="post">
<input type="hidden" name="clear" value="true">
<input type="Submit" name="Submit" value="Clear Shopping Cart">
</form>
<form action="array.asp" method="post">
<input type="hidden" name="clear" value="false">
<input type="Submit" name="Submit" value="Reload">
</form>


You're not preserving the array. Every time the page loads, you create
an array called cart, with 10 columns and 100 rows. Arrays are empty
when you first declare them. All you are doing is populating row
intItemCount with a value. That's why, as you refresh the page, you
see one (changing) value slowly crawling down the page.

Declaring such a large array as you do, when you can only use 2 cols,
is massively expensive on memory Each element in an array is a
variant, and is 16 bytes. You have created a structure in memory that
will consume 10*100*16 bytes - that's 15.625 kilobytes per session.

It's much easier, and cheaper to store your order numbers in a comma
delimited string in one session variable, along with a counter to tell
you how many there are. Then you can use the split function to convert
the string to a one-dimensional array and iterate through the elements.

<%
Dim orders, i, r1, intOrderID
Randomize Timer
r1 = Rnd
r1 = r1 * 1000000
intOrderID = 1000000 + Int (r1)

If Session("Item") = "" Then
Session("Item") = Session("Item") & intOrderID
Session("ItemCount") = 1
Else
Session("ItemCount") = Session("ItemCount") + 1
Session("Item") = Session("Item") & "," & intOrderID
End If

orders = split(Session("Item"),",")
For i = 0 to Session("ItemCount")-1
response.write i + 1 & " " & orders(i) & "<br>"
Next
%>

--
Mike Brind

Apr 12 '06 #5

Mike Brind wrote:
TRB_NV wrote:
I'm losing information from my Session when I change pages or start the same
page over again. I simplified the code so the example is really clear. The
sample code that follows is supposed to generate a random number and put it
into an Array and store it in the Session variable and then when it runs the
next time, generate another random number and display the entire Array
contents, by pulling the information out of the Session. I'd greatly
appreciate someone with fresh eyes taking a look at this code. Thanks.

<%@ LANGUAGE="VBSCRIPT" %>

<%
if Request.Form("clear") = "true" then
Session.Contents.Remove("ShoppingCart")
Session("ItemCount") = 0
clearcart = ""
end if

dim cart(999,9)

Randomize Timer
r1 = Rnd
r1 = r1 * 1000000
intOrderID = 1000000 + Int (r1)

intItemCount = Session("ItemCount")

if intItemCount = 0 then
intItemCount = 1
Session("ItemCount") = intItemCount
else
intItemCount = intItemCount + 1
Session("ItemCount") = intItemCount
end if

Session("ItemCount") = intItemCount

cart(intItemCount,1)=intOrderID
Session("ShoppingCart")=cart

xcart=Session("ShoppingCart")

for x = 1 to intItemCount
response.write x & " " & xcart(x,1) & "<br>"
next

%>
<form action="array.asp" method="post">
<input type="hidden" name="clear" value="true">
<input type="Submit" name="Submit" value="Clear Shopping Cart">
</form>
<form action="array.asp" method="post">
<input type="hidden" name="clear" value="false">
<input type="Submit" name="Submit" value="Reload">
</form>


You're not preserving the array. Every time the page loads, you create
an array called cart, with 10 columns and 100 rows. Arrays are empty
when you first declare them. All you are doing is populating row
intItemCount with a value. That's why, as you refresh the page, you
see one (changing) value slowly crawling down the page.

Declaring such a large array as you do, when you can only use 2 cols,
is massively expensive on memory Each element in an array is a
variant, and is 16 bytes. You have created a structure in memory that
will consume 10*100*16 bytes - that's 15.625 kilobytes per session.


Actually, the array you create is 10 cols by 1 thousand rows so it's
156.25 kilobytes in memory! If you have a business plan that shows you
will get 1000 orders per customer per session, lemme see it!

;-)

--
Mike Brind

Apr 13 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Adil Akram | last post by:
I've developed a shopping cart app in ASP, to secure transaction by SSL, it 've put only the checkout page in SSL but all other pages i.e. product, cart etc remains on non SSL connection. How can I...
11
by: David Lozzi | last post by:
Hello All, I am having an issue with thus far one computer on my client's web site. If the user loads the shopping cart and then closes all browser windows, then opens them back up, goes back to...
2
by: Paul Hobbs | last post by:
Hi All, I am developing a site that makes use of a standard shopping cart. Anyone can add items to the cart, but only registered users can actually check out. When a user tries to check out, if...
2
by: Joe Molloy | last post by:
Hi, This isn't a mission critical question but I thought I'dl throw it out there for your feedback as it's a bit curious. I have developed a shopping cart for an application I'm working on...
1
by: Adil Akram | last post by:
I have created a site shopping cart in ASP.net. I am using ASP session object's SessionID on non SSL connection to track session. While adding products to cart DB I insert product and SessionID...
5
by: Brad Simon | last post by:
I have written a shopping cart using ASP .NET (VB). It has been running quite successfully on a site for about a year or so. I use the SessionID to hold information on the shopping cart. I...
7
by: Joseph Byrns | last post by:
I have written a shopping cart type web application using session variables to store the shopping cart details (with a timeout of 59 minutes). Originally my timeout was set to the default 20 minute...
6
by: KevinGravelle | last post by:
What is wrong with this picture? I'm trying to set my shopping cart text on my home page using the following function that is executed when the class is constructed: protected string...
4
by: Nick Gilbert | last post by:
Hi, Is it possible to access the Session of an arbitary user from an aspx page? On an e-commerce site, I am notified of payment success via a callback from the payment server to an ASPX page...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.