Follow us on Twitter!
Ideas are far more powerful than guns.
Thursday, April 24, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 15
Guests Online: 15
Members Online: 0

Registered Members: 82889
Newest Member: Geriztul
Latest Articles
View Thread

HellBound Hackers | Computer General | Webmasters Lounge

Author

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


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-04-09 22:45
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:

Code
Name = Request.Form("Name")
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?
Author

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


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 22-04-09 00:21
What are the field data types in the in the database? Because 'a' is not a valid for the type DATETIME or similar.


Author

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


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 22-04-09 03:51
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?
Author

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


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 22-04-09 17:13
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.
Author

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


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 22-04-09 22:27
Basic insert structure has always been;

INSERT INTO Table VALUES (value1, value2, value3)

as far as i'm aware =/