0

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();
    }
}
?>
2
  • 2
    Your UPDATE statement needs a WHERE clause to specify which row(s) should be updated. If there's no WHERE clause, all rows are updated. Commented Mar 31, 2020 at 19:57
  • 1
    Also, foreach ($reponse as $v) { makes no sense at all. Commented Apr 1, 2020 at 12:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.