Reputation: 268
I have the following SQL UPDATE query using PDO and binding two parameters, but I get an error:
$updateSql = $con->prepare("UPDATE menu SET '".$field."' = :value WHERE 'id' = :idField");
$updateSql->execute(array(
':value' => $value,
':idField' => $id));
And the error is telling me:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 Syntax error next to ''dish' = ? WHERE 'id' = ?'
NOTE: The UPDATE is executed correctly, but the script stops running with the Fatal Error.
Upvotes: 1
Views: 289
Reputation: 12039
You enclosed the column name by single quotes. Remove single quotes.
$updateSql = $con->prepare("UPDATE menu SET ".$field." = :value WHERE id = :idField");
Upvotes: 1