Click to See Complete Forum and Search --> : Error Accessing database


janice
08-10-2004, 04:37 PM
I need help, urgently please.

I have just deployed my shopping cart program to the web and started getting the following error:


Error
We noticed you do not accept cookies. Please enable cookies to shop.


I have tried just about everything to get this issue resolved.

Below is the part of code that is causing this problem.

Please help if you can.

Thanks in advance.


'generates session variables with order items
Dim prodid, quantity, arrCart, scartItem
prodid = Request.Form("fproductid")
quantity = Request.Form("fquantity")
arrCart = Session("MyCart")
scartItem = Session("cartItem")

If scartItem = "" Then
Response.Redirect "error.asp?msg=" & Server.URLEncode ("We noticed you do not accept cookies. Please enable cookies to shop.")
else
if quantity <> "" AND quantity < 1 then
Response.Redirect "error.asp?msg=" & Server.URLEncode ("Please enter at least 1 as number of items you wish to order.")
end if
End If

If prodid <> "" Then
call addToCart()
Else
Dim strAction
strAction = UCase(Left(Request.Form("action"),5))
Select Case strAction
Case "CONTI" 'continue shopping
Response.Redirect "Default.asp"
Case "RECAL" 'recalculate
call recalculateCart()
Case "PROCE" 'proceed to checkout
Response.Redirect "customer.asp"
End Select
'end if for updating or inserting new item in Cart
End If

sub addToCart()
If scartItem < maxCartItems Then
scartItem = scartItem + 1
End If
Session("cartItem") = scartItem
dim rsItem, sqlProductInfo
sqlProductInfo = "SELECT * FROM products WHERE (products.catalogID=" & prodid & ")"

'open connection - returns dbc as Active connection
call openConn()
Set rsItem = Server.CreateObject("ADODB.Recordset")
rsItem.Open sqlProductInfo, dbc, adOpenForwardOnly,adLockReadOnly,adCmdText
If Not rsItem.EOF Then
arrCart(cProductid,scartItem) = rsItem("catalogID")
arrCart(cProductCode,scartItem) = rsItem("ccode")
arrCart(cProductname,scartItem) = rsItem("cname")
arrCart(cQuantity,scartItem) = CInt(quantity)
arrCart(cUnitPrice,scartItem) = rsItem("cprice")
Session("MyCart") = arrCart
End If
rsItem.Close
set rsItem = nothing
call closeConn()
end sub


sub recalculateCart()
For i = 1 To scartItem
Dim tquantity
tquantity = Request.Form("quantity" & Cstr(i))
if isempty(tquantity) OR (tquantity = "") then
tquantity = 0
elseif (tquantity < 0) OR (isnumeric(tquantity)=false) then
tquantity = 0
end if
arrCart(cQuantity,i) = CInt(tquantity)
Next
'make temp array and set it empty
ReDim temparrcart(UBound(arrCart,1),UBound(arrCart,2))
Dim tempItems
tempItems = 0
For x = 1 to UBound(arrCart,1)
For y = 1 to UBound(arrCart,2)
temparrCart(x,y) = ""
Next
Next
For i = 1 to scartItem
confirm = Request.Form("selected" & CStr(i))
zeroQuantity = arrCart(cQuantity,i)
If confirm <> "" and zeroQuantity > 0 Then
tempItems = tempItems +1
For x = 1 to UBound(arrCart,1)
temparrCart(x,tempItems) = arrCart(x,i)
Next
End If
Next
For x = 1 to UBound(arrCart,1)
For y = 1 to UBound(arrCart,2)
arrCart(x,y) = temparrCart(x,y)
Next
Next
scartItem = tempItems

Session("cartItem") = scartItem
Session("MyCart") = arrCart

end sub

CardboardHammer
08-10-2004, 05:42 PM
If Session("cartItem") has a blank value before you reach that code, then you're going to get that "error", whether or not cookies are enabled, disabled, ... baked, eaten, or crumbled.

EDIT: Just to be clear, from what's shown, it isn't a problem with database access.

janice
08-10-2004, 10:03 PM
Thanks very much for your response.

Can you help with the solution, please.

I tried to assign a value to the session variable so that it will have a value first time someone opens that page like:


Session("cartItem") = True

This is not working either.

I will appreciate any further assistance.

CardboardHammer
08-11-2004, 09:35 AM
Do you have cookies enabled? (At the very least, session cookies?)

buntine
08-11-2004, 11:02 AM
Extra note, I think that data stored in a session variable is antomatically turned into a string. Try encapsulating true in double quotes, provided you entered true.

janice
08-11-2004, 12:29 PM
CardboardHammer,
when you asked if I have cookies/session cookies enabled, do you mean on IE options menu?

If yes, I don't see that option on ie6.

When I run this code locally, it works because I had to go to iis and besides Application Name_______ I click on Create button.
With this, it works.
Where I am having the biggest headache is getting it to work on a remote server hosted by a web hosting company.

Buntine, I did what you suggested:

Session("cartItem") = "True"

It is still not working. Did I do it wrong?

I really need help.
Thanks all for the help.

CardboardHammer
08-11-2004, 01:31 PM
Originally posted by janice
CardboardHammer,
when you asked if I have cookies/session cookies enabled, do you mean on IE options menu?

If yes, I don't see that option on ie6.

...

From the menu, go to "Tools" >> "Internet Options..."

Then click on the "Privacy" tab.

Look around a bit... Click the "Advanced" button and see what you find. Or you could override the cookie handling (the "Edit" button) to allow cookies from your site cookie, without changing how other cookies are handled.

janice
08-11-2004, 01:58 PM
Once again, thanks for your continued assitance.

First, chaning the ie cookie options didn't make it work either.

Second, even if it worked, I am a bit concerned about that because it will mean instructing every user to do same.

That can't be considered efficient even though it might be done just once.

Weirdest part is that I actually already assigned a value to session variable cartItem in global.asa file like this:

Sub Session_OnStart
'Shopping cart array
Const cartAttributes = 5
Const maxCartItems = 10
ReDim arrcart(cartAttributes,maxCartItems)

Session("MyCart") = arrcart
Session("cartItem") = 1

End Sub

Yet it isn't working.

This is getting to be annoying.

lmf232s
08-11-2004, 02:13 PM
try this

'generates session variables with order items
Dim prodid, quantity, arrCart, scartItem
prodid = Request.Form("fproductid")
quantity = Request.Form("fquantity")
arrCart = Session("MyCart")
scartItem = Session("cartItem")

If scartItem <> "" Then
if quantity <> "" AND quantity < 1 then
Response.Redirect "error.asp?msg=" & Server.URLEncode ("Please enter at least 1 as number of items you wish to order.")
end if
else
Response.Redirect "error.asp?msg=" & Server.URLEncode ("We noticed you do not accept cookies. Please enable cookies to shop.")
End If


I have noticed that sometimes when I do
If something = "" then
That it does not work but When I switch it up to see if its greater then "" it works.

Also have you tried to put a
response.write sCartItem
right before your IF statement to see if sCartItem really does have a value.

janice
08-11-2004, 02:41 PM
This whole thing is weird.
If I use response.write to see the value of the value being passed to cartItem, it shows the value.

When I test it on the remote server, it is blank.
Id doesn't show 0 or 1 or anything.
Just white space.

lmf232s
08-11-2004, 02:43 PM
By chance does your remote server not support asp pages. This might have something to do with it.

I ran into this problem a while back i was going to help a buddy with a page and i was going to do all the asp and he was going to do the flash. I did my work on my computer and then uploaded it to his server and nothing. His host did not support asp. That project never happened.

Just a thought.

janice
08-11-2004, 02:50 PM
This host does support asp.
Infact they are hosting another asp site for the client.

This is really weird.

lmf232s
08-11-2004, 02:54 PM
try a
response.write Session("cartItem")
and see if you have a value for the session variable.

Maybe even try a response.write "i made it "
in the sub onload and see if it is hitting it and maybe another
reposne.write Session("cartItem") to see if it is getting set in that sub.

I dont know, just suggestions.