Syntax error in INSERT INTO statement

Results 1 to 8 of 8

Thread: Syntax error in INSERT INTO statement

  1. #1
    SteveC. Guest

    Default Syntax error in INSERT INTO statement

    The following two code snippets are from two different pages on the same website. The first one works. The second gives me this error: Syntax error in INSERT INTO statement. With the obvious exception of different variables in each, the two seem the SAME to me. But yet one works and the other doesn&#039;t. Can someone explain what I&#039;m doing wrong here?<BR><BR>SNIPPET #1:<BR><BR>ConnectionString=WhatDataBase(Request.Q ueryString("PageName"))<BR>&#039;The WhatDataBase Function returns the correct connection string<BR>&#039; for this page<BR><BR>&#039;COMPILE THE COMMAND<BR><BR>CommandString="Insert into Opinions(ContentID,Comment,SubmittedBy,DateSubmitt ed) values (" & Request.QueryString("item") & ",&#039;" & Request.Form("requiredOpinion") & "&#039;,&#039;" & Request.Form("requiredName") & "&#039;,&#039;" & now & "&#039;)"<BR><BR>&#039;ADD THE NEW RECORD TO THE DBASE<BR>Set objCommand = Server.CreateObject("ADODB.Command")<BR>objCommand .ActiveConnection=ConnectionString<BR>objCommand.C ommandText=CommandString<BR>objCommand.CommandType =adCmdText<BR>objCommand.Execute<BR><BR><BR>SNIPPE T # 2:<BR><BR>CommandString="Insert into Contacts (Name,Address,City,State,Zip,Email,Country,Passwor d,Phone) values (&#039;" & Request.Form("requiredName") & "&#039;,&#039;" & Request.Form("requiredAddress") & "&#039;,&#039;" & Request.Form("requiredCity") & "&#039;,&#039;" & Request.Form("State") & "&#039;,&#039;" & Request.Form("Zip") & "&#039;,&#039;" & Request.Form("requiredEmail") & "&#039;,&#039;" & Request.Form("requiredCountry") & "&#039;,&#039;" & Request.Form("requiredPassword") & "&#039;,&#039;" & Request.Form("Phone") & "&#039;)"<BR><BR>Set objCommand = Server.CreateObject("ADODB.Command")<BR>objCommand .ActiveConnection=UsersDBConnection<BR>objCommand. CommandText=CommandString<BR>objCommand.CommandTyp e=adCmdText<BR>objCommand.Execute<BR><BR><BR><BR>A ny and all help would be GREATLY appreciated!

  2. #2
    Join Date
    Dec 1969

    Default RE: Syntax error in INSERT INTO statement

    try response.write()ing the suspect string to the page before executing it. any problem should then become evident<BR><BR>j

  3. #3
    J. Paul Schmidt Guest

    Default INSERT vs. INSERT INTO

    You didn&#039;t say if you&#039;re using SQL Server or not.<BR><BR>But if you are, then you would want to use INSERT instead of INSERT INTO in your SQL statement. (INSERT INTO works for an Access database but not for SQL Server.)<BR><BR>Best regards,<BR>-Paul<BR><BR>J. Paul Schmidt, MBA<BR>Databases on the Web<BR><BR><BR>

  4. #4
    Mike Shaffer Guest

    Default Huh?

    "insert into" doesn&#039;t work on SQL Server? Since when? ;-)<BR><BR>

  5. #5
    Mike Shaffer Guest

    Default RE: Syntax error in INSERT INTO statement

    Is it possible that one of your data values has an embedded apostrophe? I notice that you are not checking for that.

  6. #6
    Steve Cimino Guest

    Default RE: INSERT vs. INSERT INTO

    Yeah, Mike is right. You definately can use INTO in SQL Server (at least for 7 and above). It&#039;s an optional keyword.

  7. #7
    Steve Cimino Guest

    Default RE: Syntax error in INSERT INTO statement

    Perhaps Name is a keyword... enclose it in brackets [Name], Address, etc

  8. #8
    Mike Shaffer Guest

    Default RE: Syntax error in INSERT INTO statement

    I thought so, too, but I tried it and it seemed to work just fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts