You have an error in your SQL syntax; check the manual that corresponds to your MySQL

Discussion in 'PHP' started by jenthevb, Apr 15, 2011.

  1. #1
    Hello,

    I'm new with PHP. But i hava a error that i can't fix.
    The response is

    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 ''dispatch_case' ('id', 'u_id', 'uur_start', 'dat_start', 'uur_stop', 'type_id', ' at line 1

    And the query is:
    INSERT INTO 'dispatch_case' ('id', 'u_id', 'uur_start', 'dat_start', 'uur_stop', 'type_id', 'post_id', 'subp', 'onderwerp', 'tekst', 'status_id', 'cont-pers-id', 'prio') VALUES ('NULL', 'test', '13:38', '15/04/2011', 'NULL', 'NULL', '1', '2', '', 'test1138', 'test test1136', 'Gesloten', '1', '2');

    The source code is:
    <?php
     include("inc/inc_connect_mysql.php");
    
      $query="INSERT INTO 'dispatch_case' ('id', 'u_id', 'uur_start', 'dat_start', 'uur_stop', 'type_id', 'post_id', 'subp', 'onderwerp', 'tekst', 'status_id', 'cont-pers-id', 'prio') ";
      $query .= "VALUES ('"; // let op positie van de enkele aanhalingstekens 
      $query .= 'NULL'						."', '";
      $query .= $_POST["u_id"]				."', '" ;
      $query .= $_POST["uur_start"]			."', '" ;
      $query .= $_POST["dat_start"]			."', '" ;
      $query .= 'NULL'						."', '";
      $query .= 'NULL'						."', '";
      $query .= $_POST["type_id"]			."', '" ;
      $query .= $_POST["post_id"]			."', '" ;
      $query .= $_POST["subp"]				."', '" ;
      $query .= $_POST["onderwerp"]			."', '" ;
      $query .= $_POST["tekst"]				."', '" ;
      $query .= $_POST["status_id"]			."', '" ;
      $query .= $_POST["cont-pers-id"]		."', '" ;
      $query .= $_POST["prio"]				."');" ;
      echo($query . '<br>');
      $result = mysql_query($query, $db) or die ("Er is een fout opgetreden: " . mysql_error());
    	echo("De case is ingevoerd en opgeslagen") ;
    ?>
    PHP:
     
    jenthevb, Apr 15, 2011 IP
  2. lukefowell89

    lukefowell89 Peon

    Messages:
    182
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Take the quotes off 'dispatch_case'
     
    lukefowell89, Apr 15, 2011 IP
  3. jenthevb

    jenthevb Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Done, new error:
    INSERT INTO dispatch_case ('id', 'u_id', 'uur_start', 'dat_start', 'uur_stop', 'type_id', 'post_id', 'subp', 'onderwerp', 'tekst', 'status_id', 'cont-pers-id', 'prio') VALUES ('NULL', 'test', '15:54', '15/04/2011', 'NULL', 'NULL', '1', '2', 'mosselbank', 'test1138', 'teste tstsd', 'Open', '1', '2');
    Er is een fout opgetreden: 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 ''id', 'u_id', 'uur_start', 'dat_start', 'uur_stop', 'type_id', 'post_id', 'subp'' at line 1

    i've already tryed to remove the quotes of the collums, the error is 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 "cont-pers-id', 'prio') VALUES ('NULL', 'test', '15:54', '15/04/2011', 'NU"

    mvg
     
    jenthevb, Apr 15, 2011 IP
  4. clouds

    clouds Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try putting backticks (`) around the column names instead of single quotes.
     
    clouds, Apr 15, 2011 IP
  5. ama

    ama Greenhorn

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    Try it in phpMyAdmin. It will show you the mysql code when it does the query and you can compare it with your code.
     
    ama, Apr 16, 2011 IP