Reputation: 6625
I am trying to update columns that are numbered, however I am getting a warning that these columns do not exist, even though I do have a column 1 in TRIPLECROWNpicks
SQLSTATE[42S22]: Column not found: 1054 Unknown column ''1'' in 'field list'
$sql = "UPDATE TRIPLECROWNpicks SET `:pick` = :replace WHERE `user_id` = :user_id";
$stmt = $dbh->prepare($sql);
$stmt->bindValue(':user_id', $_POST['user_id'], PDO::PARAM_INT);
$stmt->bindValue(':replace', $replace, PDO::PARAM_INT);
$stmt->bindValue(':pick', $_POST['pick'], PDO::PARAM_INT);
$stmt->execute();
Upvotes: 0
Views: 886
Reputation: 995
You bind value here and claim it to be integer.
$stmt->bindValue(':pick', $_POST['pick'], PDO::PARAM_INT);
Then you use it here as column name
SET `:pick` = :replace
There are at least two things wrong here:
Upvotes: 0
Reputation: 11610
You cannot parametrize column names.
Either you concatenate update string (not preferable -there is possibility for SQL injection) or create a map of prepared statements, and use pick property as selector for them.
Upvotes: 0
Reputation: 204766
You cannot parametrize table or column names. Only values.
So if you want to use different columns then use completly seperate queries.
Upvotes: 1