Join us at IRC!
Society leans ever heavily on computers, if you have the power to take out computers you can take out society. - cubeman372
Wednesday, May 23, 2012
Navigation
Members Online
Total Online: 35
Web Spiders: 13
Guests Online: 31
Members Online: 4

Registered Members: 70162
Newest Member: Windows-2012
Latest Articles
View Thread

HellBound Hackers | Computer General | Webmasters Lounge

Author

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

binary_10essee
Member



Posts: 15
Location: Hellbound, TN
Joined: 16.02.08
Rank:
Active User
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:

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,Descblockedription,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,Descblockedription,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?
the_dadd_from_tn2005
Author

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

c4p_sl0ck
Member



Posts: 380
Location: Sweden‮‭
Joined: 17.09.06
Rank:
God
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.



c4p_sl0ck@hotmail.com
Author

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

binary_10essee
Member



Posts: 15
Location: Hellbound, TN
Joined: 16.02.08
Rank:
Active User
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?
the_dadd_from_tn2005
Author

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

binary_10essee
Member



Posts: 15
Location: Hellbound, TN
Joined: 16.02.08
Rank:
Active User
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.
the_dadd_from_tn2005
Author

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

mambo
Member



Posts: 265
Location: The Web
Joined: 26.12.07
Rank:
Monster
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 =/


i_give_it_all@hotmail.co.uk
Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 

 

Links
By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2008- 2009. Since 3rd December 2004.