SQL INSERT INTO Error.. I'm trying to create a simple subscription page in ASP.. After spending literally hours settin up IIS.. I decided to try and script a quick HTML form that posts data to an asp page to insert the data into the relevant fields in a database. I created all files, the Database and HTML files are fine but for some reason I keep gettin this error on my SQL script.. ------------------------------------------------------------------------ Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80040E14) [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement. /DVD/Subscribe.asp, line 26 ------------------------------------------------------------------------ The ASP script file is as follows.. ------------------------------------------------------------------------ <HTML> <HEAD> <TITLE> Member Subscription </TITLE> </HEAD> <BODY> <% 'Retrieve the variables from the form Salutation = Request.querystring( "Salutation" ) Forename = Request.querystring( "Forename" ) Surname = Request.querystring( "Surname" ) Email = Request.querystring( "Email" ) %> <% 'Open the database connection Set Con = Server.CreateObject( "ADODB.Connection" ) Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Members.mdb") %> <% 'Add new member sqlAddMember = "INSERT INTO Members ( Member Salutation, Member Forename, Member Surname, Member Email Address ) VALUES ( '" & Salutation & "', '"& Forename & "', '" & Surname & "', '" & Email & "' )" Con.Execute sqlAddMember 'Display confirmation message to the user. Response.Write(Salutation & Surname & " you have been successfully added to our email list") %> ------------------------------------------------------------------------ Can any of you guys see where I'm going wrong? *Edit* After a quick further "mess about" I've came to the conclusion that the error is created by the line "Con.Execute sqlAddMember" Still dunno how to fix it though.. :spangled:
It looks to me like it could be the line above... something may not be right with the information you are trying to assign to the variable. I don't know enough about MySQL to spot anything obvious.
Thit seemed to work.. ------------------------------------------------------------------------------------- "INSERT INTO Members (`Member Salutation`, `Member Forename`) VALUES ( 'foo', 'bar' )" ------------------------------------------------------------------------------------- So its the variable that are causing the problem.. I kinda thought it might be this as I can't get my head around what the HTML text boxes are classed as when called in the calling variables section at the top. In the example I was give they were Request.form (blah) but I was unsure if that mean't that each of the text boxes were on a different form.. So I used Querystring.. I'm confused..
`Member Salutation`, `Member Forename` The quote marks around those field names are wrong. They should either be ' marks.... or realistically you shouldnt use them at all - in that case you are best off calling your fields by a single name such as MemberSalutation and MemberForename to prevent any screwups. Hope that helps.
Not a fan of ASP it's soooo sodding fickle. All will be working well then for no apparent reason it will decide that your code is wrong and break
Sorted it.. here is the fixed script... ---------------------------------------------------------------------------- <HTML> <HEAD> <TITLE> Member Subscription </TITLE> </HEAD> <BODY> <% 'Retrieve the variables from the form Salutation = Request.Form( "Salutation" ) Forename = Request.Form( "Forename" ) Surname = Request.Form( "Surname" ) Email = Request.Form( "Email" ) %> <% 'Open the database connection Set Con = Server.CreateObject( "ADODB.Connection" ) Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Members.mdb") %> <% 'Add new member sqlAddMember ="INSERT INTO Members ( `Member Salutation`, `Member Forename`, `Member Surname`, `Member Email Address`) VALUES ('" & Salutation & "', '" & Forename & "', '" & Surname & "', '" & Email & "')" con.execute sqlAddMember %> <% 'Display confirmation message to the user. Response.Write( Salutation & Surname & "you have been successfully added to our email list") %> -------------------------------------------------------------------------- Just one more thing to sort and it should just be a simple   insertion Cheers for the help guys