0

Error: INSERT INTO tbl_feedback (case) VALUES ('111111') 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 'case) VALUES ('111111')' at line 1

I bet I'm missing something simple, but would you mind taking a look at the below and let me know if you see the error? I had a longer query, but I've reduced it to just 1 value to try and troubleshoot the error with no luck. I've tried adding ticks to the table name, changing the concatenation, and removing fields. I have a working select query that uses the same table.

    require 'conn.php';
    $sql = "INSERT INTO tbl_feedback (case) VALUES ('$caseNumber')";
    if ($conn->query($sql) === TRUE) {
      echo "New record created successfully";
    } else {
      echo "Error: " . $sql . "<br>" . $conn->error;
    }
    $conn->close();
  • Hmm, 'case' is a command word in both php and sql. Maybe you should change your column name? – Vbudo May 06 '17 at 00:32
  • Brilliant! Thank you! *headdesk* – C. D. Collier May 06 '17 at 00:35
  • or quote your identifiers with `\`` – Sammitch May 06 '17 at 00:42
  • Doesn't matter if its a functional word in PHP; it's a reserved word in MySQL. Therefor you should either use a different name for that column (recommended), or wrap it in backticks, making it `INSERT INTO tbl_feedback (\`case\`) VALUES...` (I don't recommend this). – Qirel May 06 '17 at 00:43

0 Answers0