Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

ASP/SQL ... INSERT Statement Syntax Error? Bullshit?


ghost's Avatar
0 0

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?

ghost's Avatar
0 0

What are the field data types in the in the database? Because 'a' is not a valid for the type DATETIME or similar.


ghost's Avatar
0 0

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?


ghost's Avatar
0 0

Okay, these posts helped me figure it out. It was a simple mistake on my part. Here's what I did before:

INSERT (blah,blah,blah) INTO table VALUES(values)

But the field names had to go AFTER the table name. LoL. But thanks, I got it.


ghost's Avatar
0 0

Basic insert structure has always been;

INSERT INTO Table VALUES (value1, value2, value3…)

as far as i'm aware =/