View Full Version : Syntax error in INSERT INTO statement.....AARRRGGGHHHH

01-21-2007, 02:04 PM
Ok people,

Would really appreciate some help on what seems a pretty straight forward issue. I need to insert a number of values in to a table ( something that is being done on numerous occasions within the website without any issues ). However, when it comes to this particular posting page I get the following error message :

INSERT INTO tblUsers (FullName, Email_Address, Username, Password) Select 'Test_name'as fullname, 'Test@test.com' as email_address, 'Test_username' as username, 'test_password' as password

Microsoft JET Database Engine error '80040e14'

Syntax error in INSERT INTO statement.

/pencoedaafc/mailing_List_Submit.asp, line 123

I have displayed the select statement on the to the screen ( see top 3 lines ) and then get a Syntax error...

If I copy the line of code as it is and put it in to an Access query ( which is the back end DB ) then it inserts with no issues...

Any help on this one greatly appreciated...

The full code for this section is below...

set conn=server.createobject("ADODB.Connection")
set strSQL=server.createobject("ADODB.Recordset")
strMDBpath = Server.MapPath("pencoedaafc.mdb")


DIM rs_Current_Username
Set rs_Current_Username = Server.CreateObject("ADODB.Recordset")
strSQL = "Select Username From tblUsers WHERE Username = '" & strUsername & "'"

'Query the database
rs_Current_Username.Open strSQL, conn

If rs_Current_Username.BOF and rs_Current_Username.EOF THEN

Set rs_Register_User = Server.CreateObject("ADODB.Recordset")
strSQL = "INSERT INTO tblUsers (FullName, Email_Address, Username, Password) Select '" & strName & "'as fullname, '" & strEmail & "' as email_address, '" & strUsername & "' as username, '" & strpassword & "' as password"

Response.Write strSQL
rs_Register_User.Open strSQL, conn
Set rs_Register_User = Nothing

01-21-2007, 02:10 PM
Sorry people,

I was just being a numpty...Dont know why it didn't occur to me earlier but just popped in to my head. The reason it was failing was because I was using reserved words in the select statement...

Thought it was something obvious...