Syntax error in INSERT INTO and UPDATE statements

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Syntax error in INSERT INTO and UPDATE statements

    maybe this is a noob question and i've been stairing at my screen too long
    trying to find the error but I'm having problems using the Insert into and
    update statements. I have 3 diffrent forms (insert into, update, and delete) on
    the first page and depending on which form is used, a sql responce on the
    second. strangely enough the delete part works fine. any help would be
    appreciated.

    [[[[[[[[[[[[[[[[ news.cfm (form page) ]]]]]]]]]]]]]]]]]]]
    <html>
    <head>
    <title>IMAC Administrator - News</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="000066" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF"
    alink="#FFFFFF">
    <cfif "#URL.ACTION#" EQ "ADD">
    <cfoutput>
    <h2>Add News Story</h2>
    <cfform action="news2.cfm" method="post">

    <table width="740">
    <tr>
    <td width="39">Date:</td><td width="397"><cfinput name="dmy"
    value="M/D/YYYY" maxlength="10"></td>
    </tr>
    <tr>
    <td>News:</td><td><textarea name="text" cols="100" rows="5"
    wrap="OFF"></textarea></td>
    </tr>
    <tr>
    <td><input type="hidden" name="action"
    value="#url.action#"></td><td><input name="submit" type="submit" value="Add
    News"></td>
    </tr>
    </table>
    </cfform>
    </cfoutput>
    </cfif>
    <cfif "#url.ACTION#" EQ "Modify">
    <cfquery name="modify" datasource="imac">
    SELECT *
    From news
    WHERE #URL.id# = id
    </cfquery>
    <cfoutput>
    <h2>Modify News Story</h2>
    <cfform name="modify" action="news2.cfm" method="post">
    <table width="740">
    <tr>
    <td width="39">Date:</td><td width="397"><cfinput name="dmy"
    value="#modify.dmy#" maxlength="10"></td>
    </tr>
    <tr>
    <td>News:</td><td><textarea name="text" cols="100" rows="5"
    wrap="OFF">#modify.text#</textarea></td>
    </tr>
    <tr>
    <td><input type="hidden" name="id" value="#modify.id#"><input
    type="hidden" name="action" value="#url.action#"></td><td><input name="submit"
    type="submit" value="Modify News"></td>
    </tr>
    </table>
    </cfform>
    </cfoutput>
    </cfif>
    <cfif "#url.ACTION#" EQ "Delete">
    <cfquery name="delete" datasource="imac">
    SELECT *
    From news
    WHERE #URL.id# = id
    </cfquery>
    <cfoutput>
    <h2>Delete News Story</h2>
    <cfform name="delete" action="news2.cfm" method="post">

    <table width="740">
    <tr>
    <td width="39">Date:</td><td width="397"><input type="text" name="dmy"
    value="#delete.dmy#" maxlength="10" readonly="true"></td>
    </tr>
    <tr>
    <td>News:</td><td><textarea name="text" cols="100" rows="5" wrap="OFF"
    readonly="true">#delete.text#</textarea></td>
    </tr>
    <tr>
    <td><input type="hidden" name="id" value="#delete.id#"><input
    type="hidden" name="action" value="#url.action#"></td><td><input name="submit"
    type="submit" value="Delete News" onClick="return confirm('Do you really want
    to delete?')"></td>
    </tr>
    </table>
    </cfform>
    </cfoutput>
    </cfif>
    </body>
    </html>

    [[[[[[[[[[[[[[[[[[[[[ news2.cfm (sql page) ]]]]]]]]]]]]]]]]]]
    <html>
    <head>
    <title>IMAC Administrator</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#000066" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF"
    alink="#FFFFFF">
    <cfif "#form.action#" EQ "add">
    <cfquery datasource="imac" name="add">
    INSERT INTO news (dmy, text)
    VALUES (#form.dmy#, #form.text#)
    </cfquery>
    <cfoutput>News Added Sucessfully. <a href="home.cfm">Click here to return to
    IMAC Administrator Home</a></cfoutput>
    </cfif>
    <cfif '#Form.action#' EQ "modify">
    <cfquery datasource="imac" name="modify">
    UPDATE news
    SET dmy = '#form.dmy#', text = '#form.text#'
    WHERE id = #form.id#
    </cfquery>
    <cfoutput>News Modified Sucessfully. <a href="home.cfm">Click here to return
    to IMAC Administrator Home</a></cfoutput>
    </cfif>
    <cfif '#Form.action#' EQ "delete">
    <cfquery datasource="imac" name="delete">
    DELETE FROM news
    WHERE id = #form.id#
    </cfquery>
    <cfoutput>News Deleted Sucessfully. <a href="home.cfm">Click here to return
    to IMAC Administrator Home</a></cfoutput>
    </cfif>
    </body>
    </html>

    If i use the insert into form i get :
    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
    D:\Inetpub\Customers\viuxhosting\imac\imac-nyc.com\www\admin\news2.cfm: line 11

    9 : <cfquery datasource="imac" name="add">
    10 : INSERT INTO news (dmy, text)
    11 : VALUES (#form.dmy#, #form.text#)
    12 : </cfquery>
    13 : <cfoutput>News Added Sucessfully. <a href="home.cfm">Click here to
    return to IMAC Administrator Home</a></cfoutput>

    SQL INSERT INTO news (dmy, text) VALUES (M/D/YYYY, )
    DATASOURCE imac
    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.7.10)
    Gecko/20050716 Firefox/1.0.6
    Remote Address 24.161.80.163
    Referrer [url]http://imac-nyc.com/admin/news.cfm?ACTION=add[/url]
    Date/Time 11-Sep-05 12:43 PM
    Stack Trace
    at
    cfnews22ecfm1438369281.runPage(D:\Inetpub\Customer s\viuxhosting\imac\imac-nyc.co
    m\www\admin\news2.cfm:11) at
    cfnews22ecfm1438369281.runPage(D:\Inetpub\Customer s\viuxhosting\imac\imac-nyc.co
    m\www\admin\news2.cfm:11)

    if i use the update form i get:
    Error Executing Database Query.
    [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft
    Access Driver] Syntax error in UPDATE statement.

    The error occurred in
    D:\Inetpub\Customers\viuxhosting\imac\imac-nyc.com\www\admin\news2.cfm: line 19

    17 : UPDATE news
    18 : SET dmy = '#form.dmy#', text = '#form.text#'
    19 : WHERE id = #form.id#
    20 : </cfquery>
    21 : <cfoutput>News Modified Sucessfully. <a href="home.cfm">Click here to
    return to IMAC Administrator Home</a></cfoutput>

    SQL UPDATE news SET dmy = '4/11/2005', text = ' Good News! For all those
    early risers out there, morning beginner classes have been added. The beginner
    schedule is as follows:' WHERE id = 3
    DATASOURCE imac
    VENDORERRORCODE -3503
    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.7.10)
    Gecko/20050716 Firefox/1.0.6
    Remote Address 24.161.80.163
    Referrer [url]http://imac-nyc.com/admin/news.cfm?ACTION=Modify&id=3[/url]
    Date/Time 11-Sep-05 01:06 PM
    Stack Trace
    at
    cfnews22ecfm1438369281.runPage(D:\Inetpub\Customer s\viuxhosting\imac\imac-nyc.co
    m\www\admin\news2.cfm:19) at
    cfnews22ecfm1438369281.runPage(D:\Inetpub\Customer s\viuxhosting\imac\imac-nyc.co
    m\www\admin\news2.cfm:19)

    -Snowball2050


    Snowball2050 Guest

  2. Similar Questions and Discussions

    1. Error in Insert into syntax
      I donīt understand why this error is being flagged when trying to insert a new entry from a db. (Why is the flash form so tempremental? I try...
    2. Syntax error in INSERT INTO statement
      I have a two table setup in fact I am doing the blog tutorial on Macromedia but with Access and asp I have two tables topic and articles I have a...
    3. Syntax error in update
      I'm using the update record form wizard in Dreamweaver, and am getting this error when I try to submit changes. <cfparam name='FORM.buildnumber'...
    4. Getting a SQL Update syntax error...really shouldn't be?
      Try putting round the password column in the UPDATE statement. I think that SQL might be seeing that as a reserved word. Hope it helps... ...
    5. syntax error on update
      ugh, thanx for the help guess there's more than one way this syntax works as well rs("firstname")=blahblah i'm just learning sql so i tend to...
  3. #2

    Default Re: Syntax error in INSERT INTO and UPDATE statements

    text is a reserved word. rename the field or escape it [text]

    HTH
    --
    Tim Carley
    [url]www.recfusion.com[/url]
    [email]info@NOSPAMINGrecfusion.com[/email]
    Mountain Lover Guest

  4. #3

    Default Re: Syntax error in INSERT INTO and UPDATE statements

    "Text" is the name of an Access datatype, so the error is probably caused by
    the fact that you are using a reserved word as a column name. Try changing the
    the column name to something else like "NewsText".

    If "dmy" is a datetime column, consider using the createODBCDate() function or
    cfqueryparam to ensure that the date value is passed to the database correctly.
    You should also consider using cfquerparam for your where clause to prevent sql
    injection.

    ... WHERE id = #form.id# ...


    mxstu Guest

  5. #4

    Default Re: Syntax error in INSERT INTO and UPDATE statements

    many thanks tim and mxstu. forgot about the reserved words. I'll give that a try
    Snowball2050 Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139