iguider
iguider

Reputation: 721

sql update statement fails

I have an update sql statement that fails and I don't know the reason..

Is there anything wrong with:

<?php
extract($_POST);
if ($req = $db->prepare("UPDATE {$sTable} SET ? = ? WHERE id=?")) {
    $req->bind_param("ssi", $columnName, $value, $id );
    $req->execute();
}
?>

Upvotes: 1

Views: 157

Answers (1)

dev-null-dweller
dev-null-dweller

Reputation: 29462

If you bind column as string param, your query will look like:

UPDATE some_table SET 'column' = 'value' WHERE id=1

which is of course wrong. So the answer is you cannot bind column (or table) as parameter in prepared statement.

Upvotes: 2

Related Questions