CFQUERY SQL Insert Statement Failing:

Discussion in 'Programming' started by shortaug, May 21, 2008.

  1. #1
    
    <cfset field1 = #session.uname#>
    <cfset field2 = #FORM.month# & "/" & #FORM.day# & "/" & #FORM.year#>
    <cfset field3 = #FORM.field3#>
    <cfset field4 = #FORM.field4#>
    <cfset field5 = #FORM.field5#>
    
    <cfquery name="appInsert" datasource="MyDataSource">
    	insert into 
    	MyDataTable
    	(field1, field2, field3, field4, field5) 
    	values (
    		<cfqueryparam cfsqltype="CF_SQL_VARCHAR"
    				value="#field1#" />,
    		<cfqueryparam cfsqltype="CF_SQL_VARCHAR"
    				value="#field2#" />,
    		<cfqueryparam cfsqltype="CF_SQL_VARCHAR"
    				value="#field3#" />,
    		<cfqueryparam cfsqltype="CF_SQL_VARCHAR"
    				value="#field4#" />,
    		<cfqueryparam cfsqltype="CF_SQL_VARCHAR"
    				value="#field5#" />
    		)
    </cfquery>
    
    <cflocation url="index.cfm" addtoken="yes">
    
    Code (markup):
    Why is the above code giving this:


    Error Executing Database Query.
    [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

    The error occurred in LOCAL STORAGE DIRECTORY\FILE.cfm: line 21

    19 : value="#field4#" />,
    20 : <cfqueryparam cfsqltype="CF_SQL_VARCHAR"
    21 : value="#field5#" />
    22 : )
    23 : </cfquery>

    SQL insert into hours (field1, field2, field3, field4, field5) values ( (param 1) , (param 2) , (param 3) , (param 4) , (param 5) )
    DATASOURCE MyDataSource
    VENDORERRORCODE -3502
    SQLSTATE 42000
    Please try the following:

    * Check the ColdFusion documentation to verify that you are using the correct syntax.
    * Search the Knowledge Base to find a solution to your problem.

    Browser Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14
    Remote Address IP ADDRESS
    Referrer MY REFERRER
    Date/Time 21-May-08 04:18 PM
    Stack Trace
    at cfgive2ecfm379883059.runPage(LOCAL STORAGE DIRECTORY\FILE.cfm:21) at cfgive2ecfm379883059.runPage(LOCAL STORAGE DIRECTORY\FILE.cfm:21)
     
    shortaug, May 21, 2008 IP
  2. shortaug

    shortaug Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Problem solved.

    field2 was originally named date. This seems to be reserved, either by CF or Access.

    Renamed it.
     
    shortaug, May 21, 2008 IP
  3. websiteideas

    websiteideas Well-Known Member

    Messages:
    1,406
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    130
    #3
    I'm pretty sure that MS Access, and not Coldfusion uses the word "date" as a reserved word.
     
    websiteideas, May 24, 2008 IP