The Best
The Best

Reputation: 361

failed to insert into table (php mysql)

im writing a app that checks user status im using mysql and i want to have a table name check

this is my code :

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

i get error :

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'

what am i doing wrong ?

Upvotes: 0

Views: 52

Answers (2)

Nimrod007
Nimrod007

Reputation: 9913

your table name (check)

is a reserved word in MySQL.

Surround it in backticks like this:

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

Upvotes: 1

check is a reserved word in MySQL . Enclose it in backticks !

Like this

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

Upvotes: 1

Related Questions