vendredi 7 septembre 2018

Update values in database when checkbox is triggered

I am getting a list of tasks from the database and each task has a checkbox created dynamically, In the database it has a boolean value. So i'd like to update the value as soon as I check the box without having to press any submit button. Any idea on how to do that with php and javascript?

<?php } ?>
    </form>
  <table style="margin-left:  auto;margin-right:  auto;">


    <tbody>
        <?php
        // select all tasks if page is visited or refreshed
        $tasks = mysqli_query($db, "SELECT * FROM items WHERE username ='$username'" );
        $done = "";
        $i = 1; 
        while ($row = mysqli_fetch_array($tasks)) { ?>
            <tr>
                <td class="task"> <?php echo $row['task']; ?> </td>
                <td >
<?php
if ($row['done']==1) {
            echo '<input name="uploadto" type="checkbox"  checked>';

} else {
            echo '<input name="uploadto" type="checkbox"  >';
}
?>

                </td>
            </tr>
        <?php $i++; } ?>
    </tbody>
</table>




Aucun commentaire:

Enregistrer un commentaire