Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shopping cart problem

Status
Not open for further replies.

mpwright

Technical User
Sep 13, 2004
27
GB
Hi,

I am making an ASP shopping cart site and Ive used data valadation to check that valid quantities are in an "update quantities" input box. But when I hit the update quantities button I get:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "1, 2"]'
/asp/qtyupd.asp, line 21

Ive pasted the code to the stated file qtyupd.asp incase you can see anything I need to change in there:

<%

Response.Cookies("modified") = "true"
Response.Expires=0
queries = 0

Set conn = Server.CreateObject("ADODB.Connection")
Conn.Open ("driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.mappath("aspcart5.mdb"))

sql = "SELECT * FROM temporary ORDER BY item;"
set rs = Conn.Execute(sql)

do while not rs.eof
customerid= Request.Cookies("customerid")

If Request.Querystring(rs("item")) <> rs("quantity") and rs("custID") = Request.Cookies("customerid") then

newquantity = Request.QueryString("item")
Response.write(newquantity)

if newquantity = 0 then
sql = "DELETE DISTINCTROW custID FROM temporary WHERE (item='" & rs("item") & "')"
else
sql = "UPDATE DISTINCTROW temporary SET quantity ='" & newquantity & "' WHERE item='" + rs("item") + "' AND custID='" + customerid + "'"
end if

set rs = Conn.Execute(sql)

sql = "SELECT * FROM temporary ORDER BY item;"
set rs = Conn.Execute(sql)

end if

if not rs.eof then rs.movenext
loop

rs.close
set rs = nothing

Response.Redirect("refview.asp")


%>


 
All Request values come over as strings. What I see here is that you are comparing them to numerical values.

Try this for starters.

Code:
If CLng(Request.Querystring(rs("item"))) <> rs("quantity") and rs("custID") = Request.Cookies("customerid") then 

newquantity = CLng(Request.QueryString("item"))
Response.write(newquantity)

Using the CLng conversion method twice in the above example.

ToddWW
 
Using the above I get the error:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'CLng'
/asp/qtyupd.asp, line 18
 
Well, let me put it simply. Any Request calls are going to return strings. Even if they are numbers. If you are trying to compare them to numbers, you will have to first convert them using CInt or CLng. Not knowing what your RS field types are, it is going to be hard to troubleshoot this for you. Maybe you can re-post the code that your modified, but still generated an error. That might help.

ToddWW
 
Heres the code I modified, sorry about the questions but im fairly new to asp & learning as I go.

<%

Response.Cookies("modified") = "true"
Response.Expires=0
queries = 0

Set conn = Server.CreateObject("ADODB.Connection")
Conn.Open ("driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.mappath("aspcart5.mdb"))

sql = "SELECT * FROM temporary ORDER BY item;"
set rs = Conn.Execute(sql)

do while not rs.eof
customerid= Request.Cookies("customerid")

If CLng(Request.Querystring(rs("item"))) <> rs("quantity") and rs("custID") = Request.Cookies("customerid") then

newquantity = CLng(Request.QueryString("item"))
Response.write(newquantity)


if newquantity = 0 then
sql = "DELETE DISTINCTROW custID FROM temporary WHERE (item='" & rs("item") & "')"
else
sql = "UPDATE DISTINCTROW temporary SET quantity ='" & newquantity & "' WHERE item='" + rs("item") + "' AND custID='" + customerid + "'"
end if

set rs = Conn.Execute(sql)

sql = "SELECT * FROM temporary ORDER BY item;"
set rs = Conn.Execute(sql)

end if

if not rs.eof then rs.movenext
loop

rs.close
set rs = nothing

Response.Redirect("refview.asp")


%>
 
also in the requesting of the qty values, you will probably want/need a zero length check on it as well just in case someone just deletes the stuff out of the box, so you can default it to zero before trying to change it from string to numeric and throwing an error on that step. ex:

qty = request("qty")
if qty <> "" then
If IsNumeric(qty) then
qty = cint(qty)
else
qty = 0
end if
Else
qty = 0
End If

gets you converted, zero length checked and also makes sure it's not qty of "W" and defaults to 0 on any issues not a number

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
You have a doubled up form input on the previous page. Anytime you get multiple values for a single input when your expecting only one value it means you have two inputs with the same name. This will cause them to get poassed as a comma-space delimited string.

I agree that you should add some isNumeric validation on the server side, but you need to go back to the previous page first and figure out why there are two inputs with the same name and get rid of the offending one that is passing the extra (unnecessary) value.

-T

barcode_1.gif
 
to be honest im not sure why there are 2 inputs with the same name. Im picking this site up from where my (more experienced)predecessor left it so Im fairly new to both HTML, ASP & Java In this thread: I was helped along & managed to get rid of the 2 item problem. So im stumped as to where to go from here. The code that I was told to use is on this page.

Kind Regards
 
Hi,

Thanks for the info, Im not sure where I need to put the code that Drexor said, could someone point me in the right direction please.

Regards

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top