I've got an issue regarding my UPDATE
statement. When I want to update a column, it just doesn't let me to do that.
I tried to use a binded value for updating the column, I expected for it to change it but it didnt do that.
I wanted it to update the column which was the thing that I expected, but it didnt work.
Here's the code that I am struggling with:
$updatecolor = $conn->prepare("UPDATE avatar SET :part=:color WHERE user_id=:id");
$updatecolor->bindParam(':part', $part, PDO::PARAM_STR);
$updatecolor->bindParam(':color', $color, PDO::PARAM_STR);
$updatecolor->bindParam(':id', $myu->id, PDO::PARAM_INT);
$updatecolor->execute();
CodePudding user response:
You can't bind param the name of a column. Perhaps use if statements to do this correctly.
if($part == "soandso"){
$updatecolor = $conn->prepare("UPDATE avatar SET soandso=:color WHERE
user_id=:id");
$updatecolor->bindParam(':color', $color, PDO::PARAM_STR);
$updatecolor->bindParam(':id', $myu->id, PDO::PARAM_INT);
$updatecolor->execute();
} elseif($part == "soandso2"){
// you get the idea