I wanted to update my SQL database with a PHP array, which is completed by users in another page. I made a nested foreach with one that runs through my table and the other through the database to modify each row with the new values in the table; instead it ran without errors, but put the last values in the table to each row in the database.
Here the code for the database update
<?php
@$rea = $_POST[rea];
$bdd = new PDO('mysql:host=localhost;dbname=si6;charset=utf8', 'root', '');
$reponse = $bdd->prepare("update ca set rea = :rea");
print_r($rea);
foreach ($reponse as $v) {
foreach ($rea as $value) {
$reponse->bindValue(':rea', $rea[$value], PDO::PARAM_STR);
$reponse->execute();
}
}
?>
UPDATEstatement needs aWHEREclause to specify which row(s) should be updated. If there's noWHEREclause, all rows are updated.foreach ($reponse as $v) {makes no sense at all.