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,071
  • 9
  • 27
  • 36
Nimrod007
  • 9,469
  • 8
  • 46
  • 70

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
  • 20,688
  • 4
  • 50
  • 67
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
  • 32,630
  • 16
  • 65
  • 80