I'm making a game using PHP with MySQL and I need an UPDATE query where the fields names could change from one user to another.
My code is:
$upd = $sql->prepare("UPDATE empire_users SET :p = :p + :p2 WHERE id = :id");
$upd->execute(array(
':p' => "p".$type,
':p2' => 10,
':id' => $_SESSION["id"]
));
In my database, users have 3 columns : pwood, pstone, pwheat, and $type could only be "wheat", "stone", or "wood".
I want to update the selected field (which depends of $type) to increase by p2 (here 10).