mardi 21 juillet 2015

Php update multiple row with checkbox

Hello i would like to UPDATE all the row with a Boolean ( 1 ) when i check the checkbox , but i can't do it when i try.. He select and update all "$id" or update only the last $id of my cours table.

Someone can help ? :)

<?php
        require 'inc/db.php';
        $req = $pdo->query('SELECT * FROM cours WHERE isValid = 0' );
        while ($row = $req->fetch(PDO::FETCH_ASSOC))
        {
            $originalDate = $row['date'];
            $newDate = date("d-m-Y", strtotime($originalDate));
            $id = $row['id'];


            echo "<tr>";
            echo "<td>" . htmlspecialchars($newDate) . "</td>";
            echo "<td>" .  htmlspecialchars($row['hours']) . "</td>";
            echo "<td>" . htmlspecialchars($row['iduser']) . " / " . htmlspecialchars($row['lastname']) . " / " . htmlspecialchars($row['firstname']) . "</td>";
            echo "<td>" . htmlspecialchars($row['courses']) . "</td>";
            print "<form action='' method='POST'>
                    <div class='form-group'>";
            echo  "<td><input type='checkbox' name='check[$id]' value='1' >" . $id  ."</td>"; // Problem is here

            echo "</div>";

            print "</tr>";



        }

        print "</table>";

        if(isset($_POST['check'])) {

            foreach ($_POST['check'] as $report_id) {

                echo "$report_id was checked! ";
                //$req2 = $pdo->prepare("UPDATE cours SET isValid = 1 WHERE id = '$id'");
                //$req2->execute();
            }

            var_dump($id);
        }





        ?>
            <button type="submit" name="send" class="btn btn-primary center-block" >Send</button>
        <?php print '</form>'?>




Aucun commentaire:

Enregistrer un commentaire