SQL error in DELETE statement

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

  1. #1

    Default SQL error in DELETE statement

    I am working on a page that deletes a record from a database. Everything seems to be right to me and I can't figure out what is wrong. The SQL is
    identical to another similar page I created which works. Here is the error CF is giving me.
    --------------------------------------------
    Error Occurred While Processing Request
    Error Executing Database Query.
    Syntax error or access violation message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
    version for the right syntax to use near ''johndoe' WHERE id = 9' at line 1"

    The error occurred in C:\CFusionMX\wwwroot\picturesbyjulie\deleting_img. cfm: line 9

    7 : <cfquery name="delete_img" datasource="picsbyjulie" username="root" password="******">
    8 : DELETE FROM '#getusertable.user_table#'
    9 : WHERE id = '#URL.id#' <----ERROR HERE
    10 : </cfquery>
    11 : <cflocation url="edit_pictures.cfm?f=#getusertable.firstname#& l=#getusertable.lastname#&message=img_deleted">

    SQL DELETE FROM 'johndoe' WHERE id = 9 <--This is the correct value that should be passed with the URL.
    DATASOURCE picsbyjulie
    VENDORERRORCODE 1064
    SQLSTATE 42000
    --------------------------------------------

    Here is the complete action page.

    --------------------------------------------
    <cfif IsDefined("URL.f") AND IsDefined("URL.l") AND IsDefined("URL.id") AND #URL.f# NEQ "" AND #URL.l# NEQ "" AND #URL.id# NEQ "">
    <cfquery name='getusertable' datasource="picsbyjulie" username="root" password="*********">
    SELECT firstname, lastname, user_table
    FROM picsbyj.user_cf
    WHERE firstname='#URL.f#' AND lastname='#URL.l#'
    </cfquery>
    <cfquery name="delete_img" datasource="picsbyjulie" username="root" password="*********">
    DELETE FROM '#getusertable.user_table#'
    WHERE id = '#URL.id#'
    </cfquery>
    <cflocation url="edit_pictures.cfm?f=#getusertable.firstname#& l=#getusertable.lastname#&message=img_deleted">
    <cfelse>
    <cflocation url="edit_pictures.cfm?f=#getusertable.firstname#& l=#getusertable.lastname#&message=failed">
    </cfif>
    -------------------------------------------

    Thanks,
    stillwaiting
    stillwaiting Guest

  2. Similar Questions and Discussions

    1. Update Statement error
      Hello, Ii'm receiving the syntax error listed below for my update statement. Doesn't anyone have any ideas? Syntax error or access...
    2. Syntax error in Where Statement
      Having a problem with what the server says is a syntax error in the Where statement, but cant figure out where it is. <cfif ...
    3. SQL statement error
      when I use the following select statment and code: <% blah blah etc etc..... Set rsCodevault = Server.CreateObject("ADODB.Recordset") strSQL...
    4. Restricting the number of rows in delete statement
      Folks: I am trying to find out what is the best way to restrict the number of rows deleted in a single statement (so as to not blow out the...
    5. Error when using include statement
      1. You have the first line commented out 2. you are not embedding quotes properly. Try (multiple lines to avoid email problems): ...
  3. #2

    Default Re: SQL error in DELETE statement

    Get rid of the quotes around the tablename.

    Originally posted by: Newsgroup User
    I am working on a page that deletes a record from a database. Everything seems
    to be right to me and I can't figure out what is wrong. The SQL is
    identical to another similar page I created which works. Here is the error CF
    is giving me.
    --------------------------------------------
    Error Occurred While Processing Request
    Error Executing Database Query.
    Syntax error or access violation message from server: "You have an error in
    your SQL syntax; check the manual that corresponds to your MySQL server
    version for the right syntax to use near ''johndoe' WHERE id = 9' at line 1"

    The error occurred in C:\CFusionMX\wwwroot\picturesbyjulie\deleting_img. cfm:
    line 9

    7 : <cfquery name="delete_img" datasource="picsbyjulie" username="root"
    password="******">
    8 : DELETE FROM '#getusertable.user_table#'
    9 : WHERE id = '#URL.id#' <----ERROR HERE
    10 : </cfquery>
    11 : <cflocation
    url="edit_pictures.cfm?f=#getusertable.firstname#& l=#getusertable.lastname#&mess
    age=img_deleted">

    SQL DELETE FROM 'johndoe' WHERE id = 9 <--This is the correct value that
    should be passed with the URL.
    DATASOURCE picsbyjulie
    VENDORERRORCODE 1064
    SQLSTATE 42000
    --------------------------------------------

    Here is the complete action page.

    --------------------------------------------
    <cfif IsDefined("URL.f") AND IsDefined("URL.l") AND IsDefined("URL.id") AND
    #URL.f# NEQ "" AND #URL.l# NEQ "" AND #URL.id# NEQ "">
    <cfquery name='getusertable' datasource="picsbyjulie" username="root"
    password="*********">
    SELECT firstname, lastname, user_table
    FROM picsbyj.user_cf
    WHERE firstname='#URL.f#' AND lastname='#URL.l#'
    </cfquery>
    <cfquery name="delete_img" datasource="picsbyjulie" username="root"
    password="*********">
    DELETE FROM '#getusertable.user_table#'
    WHERE id = '#URL.id#'
    </cfquery>
    <cflocation
    url="edit_pictures.cfm?f=#getusertable.firstname#& l=#getusertable.lastname#&mess
    age=img_deleted">
    <cfelse>
    <cflocation
    url="edit_pictures.cfm?f=#getusertable.firstname#& l=#getusertable.lastname#&mess
    age=failed">
    </cfif>
    -------------------------------------------

    Thanks,
    stillwaiting




    Dan Bracuk Guest

  4. #3

    Default Re: SQL error in DELETE statement

    Duh.
    <img src="http://img35.echo.cx/img35/2365/bonk4tt.gif" alt="Hammer 2" />

    Whenever it is something difficult, I figure it out. When it is so simple, that's another story. grrrr.

    Thanks Dan
    > Get rid of the quotes around the tablename.
    stillwaiting 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