mySQL delete query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • php coder

    mySQL delete query

    Sorry, this is simple... but i'm going cross-eyed trying to find the
    error:
    This code:
    $delete_query = "DELETE FROM $tablename WHERE index = '$index'";
    if($delete){
    mysql_query($de lete_query) or die(mysql_error ());
    }

    is throwing this error:
    Couldn't run query: You have an error in your SQL syntax near 'index =
    15' at line 1

    And everything I'm referencing says the coding is correct.
    Any ideas? suggestions?

    Thanks!

  • David Haynes

    #2
    Re: mySQL delete query

    php coder wrote:[color=blue]
    > Sorry, this is simple... but i'm going cross-eyed trying to find the
    > error:
    > This code:
    > $delete_query = "DELETE FROM $tablename WHERE index = '$index'";
    > if($delete){
    > mysql_query($de lete_query) or die(mysql_error ());
    > }
    >
    > is throwing this error:
    > Couldn't run query: You have an error in your SQL syntax near 'index =
    > 15' at line 1
    >
    > And everything I'm referencing says the coding is correct.
    > Any ideas? suggestions?
    >
    > Thanks!
    >[/color]
    The only thing that springs to mind is that index is a reserved word.
    Have you tried echoing $delete_query and then cutting and pasting it
    into a mysql command line session?

    -david-

    Comment

    • Jerry Stuckle

      #3
      Re: mySQL delete query

      php coder wrote:[color=blue]
      > Sorry, this is simple... but i'm going cross-eyed trying to find the
      > error:
      > This code:
      > $delete_query = "DELETE FROM $tablename WHERE index = '$index'";
      > if($delete){
      > mysql_query($de lete_query) or die(mysql_error ());
      > }
      >
      > is throwing this error:
      > Couldn't run query: You have an error in your SQL syntax near 'index =
      > 15' at line 1
      >
      > And everything I'm referencing says the coding is correct.
      > Any ideas? suggestions?
      >
      > Thanks!
      >[/color]

      In addition to index being a reserved word (needs to be in back tickies,
      i.e. `index`), 15 looks to be a numeric value - and therefore should NOT
      be in single quotes.

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • Iván Sánchez Ortega

        #4
        Re: mySQL delete query

        -----BEGIN PGP SIGNED MESSAGE-----
        Hash: SHA1

        php coder wrote:
        [color=blue]
        > Couldn't run query: You have an error in your SQL syntax near 'index =
        > 15' at line 1[/color]

        Is there a column named "index" in that table?

        - --
        - ----------------------------------
        Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net


        Proudly running Debian Linux with 2.6.12-1-686 kernel, KDE3.5.0, and PHP
        5.1.1-1 generating this signature.
        Uptime: 10:18:43 up 2 days, 12:55, 1 user, load average: 0.39, 0.20, 0.12

        -----BEGIN PGP SIGNATURE-----
        Version: GnuPG v1.4.2 (GNU/Linux)

        iD8DBQFDy2US3jc Q2mg3Pc8RAot6AJ sHBlMfC6tFdy/lrMJgUSEz3277TA CeMUsn
        5L8z4GRzhQPBMUD HzqYMJFI=
        =MJKd
        -----END PGP SIGNATURE-----

        Comment

        • Pedro Graca

          #5
          Re: mySQL delete query

          php coder wrote:[color=blue]
          > This code:
          > $delete_query = "DELETE FROM $tablename WHERE index = '$index'";[/color]
          _______________ _______________ _______^______^

          [color=blue]
          > is throwing this error:
          > Couldn't run query: You have an error in your SQL syntax
          > near 'index = 15' at line 1[/color]
          _______???__
          What happened to te quotes?

          --
          Mail to my "From:" address is readable by all at http://www.dodgeit.com/
          == ** ## !! ------------------------------------------------ !! ## ** ==
          TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
          may bypass my spam filter. If it does, I may reply from another address!

          Comment

          • J B Carr

            #6
            Re: mySQL delete query

            php coder wrote:[color=blue]
            > Sorry, this is simple... but i'm going cross-eyed trying to find the
            > error:
            > This code:
            > $delete_query = "DELETE FROM $tablename WHERE index = '$index'";
            > if($delete){
            > mysql_query($de lete_query) or die(mysql_error ());
            > }
            >
            > is throwing this error:
            > Couldn't run query: You have an error in your SQL syntax near 'index =
            > 15' at line 1
            >
            > And everything I'm referencing says the coding is correct.
            > Any ideas? suggestions?
            >
            > Thanks!
            >[/color]
            I suggest:

            $q = "Delete from" . $tbl_name . " where index=" . $index; //if index an
            integer, or

            $q = "Delete from" . $tbl_name . " where index='" . $index . "'"; //if
            index a string

            Comment

            Working...