2

this call fails with error :

mysqli_report(MYSQLI_REPORT_ALL);
$stmt = $mysqli->prepare("INSERT INTO check VALUES (?,?,?,?,?,?)");

error i get :

Uncaught exception 'mysqli_sql_exception' with 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 'check VALUES (?,?,?,?,?,?)' at line 1'

  1. I have a table named "check" with right amount of fields
  2. if i change table name to checkSomething it works ...

any idea ?

George Brighton
  • 5,131
  • 9
  • 27
  • 36
Nimrod007
  • 9,825
  • 8
  • 48
  • 71

2 Answers2

3

check is a reserved keyword. To use it as table name, you have to escape it with backticks like this: `check` :

$stmt = $mysqli->prepare("INSERT INTO `check` VALUES (?,?,?,?,?,?)");
Filipe Silva
  • 21,189
  • 5
  • 53
  • 68
2

Check is a reserved word in MySQL. You need to either surround it in backticks like this:

$mysqli->prepare("INSERT INTO `check` VALUES (?,?,?,?,?,?)");

Or much better, rename it to something that you don't need to constantly have a special case for.

$mysqli->prepare("INSERT INTO checks VALUES (?,?,?,?,?,?)");
Fluffeh
  • 33,228
  • 16
  • 67
  • 80