Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
ASP/SQL ... INSERT Statement Syntax Error? Bullshit?
Okay, so I'm working on a small web site that a friend requested. I have this form. You click "Done!" and it's supposed to put the information from the form into the database. I am using a MS Access DB and Classic ASP.
Here's the code I tried:
EMail = Request.Form("EMail")
Phone = Request.Form("Phone")
Make = Request.Form("Make")
Model = Request.Form("Model")
aYear = Request.Form("Year")
Desc = Request.Form("Desc")
aDate = Request.Form("Date")
If (Name = "") Or (EMail = "") Or (Phone = "") Or (Make = "") Or (Model = "") Or (aYear = "") Or (aDate = "") Then
Response.Write "Oops! There was an error with your request. Please make sure you fill in ALL required fields and try again."
Else
If Desc = "" Then
Desc = "(None)"
End If
Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
strConnection = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("/downsouthaudio/db/servicerequestdb.mdb")
Conn.Open(strConnection)
aQuery = "INSERT INTO Requests (Name,EMail,Phone,VehicleMake,VehicleModel,VehicleYear,Description,DateTime) VALUES ('" & Name & "','" & EMail & "','" & Phone & "','" & Make & "','" & Model & "','" & aYear & "','" & Desc & "','" & aDate & "')"
' Response.Write aQuery
Conn.Execute(aQuery)
Conn.Close```
If I use that I get this message:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
It says Line 28. (Which is where the "INSERT" code is (above).
If I call the Response.Write line above (it's commented out) it prints the following: (I used all a's for testing)
INSERT INTO Requests (Name,EMail,Phone,VehicleMake,VehicleModel,VehicleYear,Description,DateTime) VALUES ('a','a','a','a','a','a','(None)','a')
How is that causing a syntax error? If I do:
INSERT INTO Requests (Name) VALUES ('Blah')
and execute it, it works without any problem. I've Google'd for a little while with no luck. This is the first time I've touched Classic ASP in a while. =P
Any suggestions?
They're all text. I just now got the darn thing workin'. All I had to do was:
INSERT INTO Requests VALUES (blah, blah, blah)
instead of: INSERT field,field,field,blah,blah INTO Requests VALUES (blah, blah, blah)
It doesn't make sense to me why that would fix the problem. But it works now. Does that sound right, or should it work either way?