A
A
Alexey2018-04-09 17:01:31
PHP
Alexey, 2018-04-09 17:01:31

How to write checkbox value to MySQL table?

There is a table dynamically generated from the database with checkboxes in one of the columns:

<table style="width: 1000;" id="activeTable" class="editableTable" overflow = "scroll">
        <thead class="t_hdr">
            <tr class="header">
 
                <td><b>ID</b></td>
                <td><b>Изготовитель</b></td>
                <td><b>Адрес</b></td>
                <td><b>Печать</b></td>
                
            </tr>
        </thead>
        <tbody>
 
            <input type="submit" class="my_button" name="update" value="UPDATE" style="width: 270px"/><br>
    <?  $i = 0;
        while ($row = $Result->fetch_assoc()) {
        $i++;
        //$sql = $Database -> query("UPDATE izgotoviteli SET stamp = 0 WHERE id = $i");
    ?>
                
                <tr  id="z_<?=$i?>">
                <td name = "post_id"><?=$row['id']?></td>
                <td><?=$row['izgotovitel']?></td>
                <td><?=$row['adress']?></td>
        <td><label check></label><input type="checkbox" name="stamp[]" value="<?=$row['stamp']?>" <? if($row['stamp'] == 1)echo $check ?> onchange="save()" ></td>
                </tr>
                <? } ?> 
            </tbody>
        </table>

It turned out to make the checkbox values ​​read from the database (tinyint(1) type is used: 1-checkbox, 0-no checkbox):
<label check></label><input type="checkbox" name="stamp[]" value="<?=$row['stamp']?>

But how to make the value 0 or 1 entered into the database if you check the checkbox?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question