lundi 22 février 2016

PHP - Checkbox in table not returning any value

When I click the delete button, the values of those checkboxes that are checked in the table are not shown. It is suppose to delete records on the database based on the id but i'm stuck in getting the value of the checkboxes. Please help correct my code. I'm using bootstrap for your information.

PHP

$sql = "SELECT id, title FROM box";
$query = mysqli_query($db, $sql);

if(isset($_POST['btnDelete'])) {
    $checkbox = isset($_POST['chkDelete']) ? $_POST['chkDelete'] : array();


    for($i=0;$i<count($checkbox);$i++)
    {
        $message = $checkbox[$i];
    }
}

HTML

<div class="content">
            <div id="table">
                <table class="col-md-12 table-bordered table-striped table-condensed cf">
                    <thead class="cf">
                        <tr>
                            <th></th>
                            <th>#</th>
                            <th>Title</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                            while($result = mysqli_fetch_array($query))
                            {
                                $html = '<tr>
                                            <td data-title="">
                                                <input name="chkDelete[]" type="checkbox" value="' . $result['id'] . '">
                                            </td>
                                            <td data-title="#">' . $result['id'] . '</td>
                                            <td data-title="Title">' . $result['title'] . '</td>
                                            <td data-title="Action">
                                                <a href="edit.php?id=' . $result['id'] . '">Edit</a>
                                            </td>
                                         </tr>';

                                echo $html;
                            }
                        ?>
                    </tbody>
                </table>
            </div>
            <form action="" method="POST">
                <input type="submit" name="btnDelete" value="Delete" />
            </form>
            <div class="message"><?php echo $message;?></div>
        </div> <!--//END content-->




Aucun commentaire:

Enregistrer un commentaire