1 Reply Latest reply on Aug 20, 2007 4:05 AM by Newsgroup_User

    SQL syntax error?

    Sketman
      Hello!

      I am trying to create a delete page. I have built a master page with the list of records in table format and dynamically created a "delete" link from master page to delete page. Record ID is passed via variable in URL.

      Now my problem is, that when the delete link in master page is clicked, I get the following error message:
      "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 '` WHERE ID_projektu=16' at line 1"

      This message started to show after I had implemented the Delete record server behavior. Before that the link worked fine, it redirected from master page to delete page and showed all the details. Everything went wrong after implementing the Delete page server behavior.

      Here is my delete record code, where ID_projektu_vymaz is a record identification variable passed via URL, 1st_projekty is a database table and ID_projektu is a table column with the ID of records.

      if ((isset($_GET['ID_projektu_vymaz'])) && ($_GET['ID_projektu_vymaz'] != "")) {
      $deleteSQL = sprintf("DELETE FROM ``1st_projekty`` WHERE ID_projektu=%s",
      GetSQLValueString($_GET['ID_projektu_vymaz'], "int"));

      mysql_select_db($database_MySql, $MySql);
      $Result1 = mysql_query($deleteSQL, $MySql) or die(mysql_error());

      $deleteGoTo = "projekty_edituj.php";
      if (isset($_SERVER['QUERY_STRING'])) {
      $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
      $deleteGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $deleteGoTo));
      }

      Any idea why I get this error message please?

      Thanks in advance.
        • 1. Re: SQL syntax error?
          Level 7
          Sketman wrote:
          > $deleteSQL = sprintf("DELETE FROM ``1st_projekty`` WHERE ID_projektu=%s",
          > GetSQLValueString($_GET['ID_projektu_vymaz'], "int"));

          Remove the extra backticks from around 1st_projekty:

          $deleteSQL = sprintf("DELETE FROM `1st_projekty` WHERE ID_projektu=%s",
          GetSQLValueString($_GET['ID_projektu_vymaz'], "int"));

          --
          David Powers, Adobe Community Expert
          Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
          Author, "PHP Solutions" (friends of ED)
          http://foundationphp.com/