2
votes

I'm trying to make an ID (primary key and autoincrement) from the MS Access database to be used as a login pass. But I'm receiving this error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

And here is my code:

con.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="& Server.MapPath("db.mdb") &""
sql="SELECT * FROM tblLogin WHERE ID='" & request.form("id") & "';"

rs.CursorType=2

rs.Open sql,con

if rs.bof then
   response.redirect "loginpage.asp?msg=ID does not exist."
else
   response.redirect "adminpage.asp"
end if

Please correct me if I'm missing something or any solutions that you recommend.

Thanks in advance.

2
It look alike you are sending ID as a string. Should it be an int? If so drop the apostrophe's around it. - StephenCollins
Oh thanks. I already removed the quotation marks and I received this error: [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed. Any solutions? - user3130849
Can I see your sql= line of code - StephenCollins
this one? sql="SELECT * FROM tblLogin WHERE ID='" & request.form(id) & "';" - user3130849
Try it like this and see what happens... sql="SELECT * FROM tblLogin WHERE ID=" & request.form("id") - StephenCollins

2 Answers

5
votes

Change:

sql="SELECT * FROM tblLogin WHERE ID='" & request.form("id") & "';"

to

sql="SELECT * FROM tblLogin WHERE ID=" & request.form("id")

Then check like this:

If rs.EOF then
   response.redirect "loginpage.asp?msg=ID does not exist."
else
   response.redirect "adminpage.asp"
end if
0
votes

Check 3 things:

  1. make sure the form in previous page is submitted by POST method not GET.
  2. remove single quote around the id as it is not a string (if ID column is integer) (@meda answer)
  3. use if not rs.eof instead of if not rs.bof

And a security warning besides of your question:

before redirecting to admin page, undoubtedly you need some logic to set session or cookie to determine if real admin is going to target page. it seems that your admin page has no logic to check if user is coming from login page or coming there suddenly!