I’m using PDO, and my $_POST['arraywithdata'] is an array filed with numeric values. I think that this is not enough secure, I just wan’t to be sure and prevent myself from a hack.
This is my code:
$arr = $_POST['arraywithdata'];
$SQL->query("UPDATE `data_s` SET `set` = 1 WHERE `id` IN " . implode(", ", $arr));
As you can see, I’m not checking if the post code in a int or something.
Should I rather use something like:
implode(", ", (int) $arr)
?
I guess the above will not work, since array can not be an integer.
You need to convert each value of the array and not the array itself. You can use
array_mapto do so:Here
array_mapwill applyintvalto each value of$arrand return a new array with the return values.But as you’re using PDO, you might also be interested in a PDO solution.