I'm trying to do a simple shopping cart and am having problems with the following code. All I'm trying to do is read in the cookie with the items in it and add them to an array. Then add the new item to the array and re-write the cookie.
The problem is i never get the items I wrote to the cookie if I do a for each loop. Any help would be appreciated.
<%
dim cartItems()
dim i,j
i=0
if Request.Cookies("Cart"
.Haskeys = true then
For Each objCK In Request.Cookies("Cart"
redim Preserve cartItems(i)
cartItems(i)=Request.Cookies(objCK)
i = i + 1
Next
end if
If Request.QueryString("ProdCode"
<> "" then
redim Preserve cartItems(i)
cartItems(i) = Request.QueryString("ProdCode"
i = i + 1
end if
if i <> 0 then
for j = 0 to (i-1)
Response.Cookies("Cart"
("Item" & j) = cartItems(j)
next
end if
Response.Redirect("cuCart.asp?ProdCode="&Request.QueryString("ProdCode"
)
%>
The problem is i never get the items I wrote to the cookie if I do a for each loop. Any help would be appreciated.
<%
dim cartItems()
dim i,j
i=0
if Request.Cookies("Cart"
For Each objCK In Request.Cookies("Cart"
redim Preserve cartItems(i)
cartItems(i)=Request.Cookies(objCK)
i = i + 1
Next
end if
If Request.QueryString("ProdCode"
redim Preserve cartItems(i)
cartItems(i) = Request.QueryString("ProdCode"
i = i + 1
end if
if i <> 0 then
for j = 0 to (i-1)
Response.Cookies("Cart"
next
end if
Response.Redirect("cuCart.asp?ProdCode="&Request.QueryString("ProdCode"
%>