I am trying to build a query from the values of an array so far I have,
$itemPlus = $_POST['itemPlus'];
$query = implode(', ', array_map(function($items) {return $items . ' = ' . $items . '-?';}, $items));
// $query = 'hats = hats-?, gloves = gloves-?, scarfs = scarfs-?'
$params = implode(', ', $userCost);
// $params = '10, 7, 9'
$q = $dbc -> prepare("UPDATE items SET " . $query . ", $itemPlus = $itemPlus+1 WHERE id = ?");
$q -> execute(array($params, $account['id']));
It doesn’t work, this is my first time trying this and as it doesn’t work I am obviously doing something wrong!?
Thanks
Since
$paramsis a string of values, you cannot make it into an array along with$account['id']. Instead.use the array that created it$userCost:Since
$itemPlusis coming from$_POST, you will need to be sure that is valid input. Since it refers to a column name, it is recommended to use a whitelist for that: