Adi
Adi

Reputation: 4904

Submit Dynamically created HTML CheckBoxes to Database(MySQL)

Technologies: HTML, JS, PHP, MySQL

I have some rows of data which are dynamically created. Now I want to update some rows which are checked by user for editing. It may be all rows OR some of them. Like this

enter image description here

I have created ids of these rows like "checkbox_[Id of data in database]"

Now I want to update data. how can I take checked Ids with $_POST to update?

Upvotes: 0

Views: 571

Answers (1)

Jonas S'jegers
Jonas S'jegers

Reputation: 101

<form action="test.php" method="post">
<input type="checkbox" name="check_list[]" value="value 1">
<input type="checkbox" name="check_list[]" value="value 2">
<input type="checkbox" name="check_list[]" value="value 3">
<input type="checkbox" name="check_list[]" value="value 4">
<input type="checkbox" name="check_list[]" value="value 5">
<input type="submit" />
</form>
<?php
if(!empty($_POST['check_list'])) {
    foreach($_POST['check_list'] as $check) {
            echo $check; //echoes the value set in the HTML form for each checked checkbox.
                         //so, if I were to check 1, 3, and 5 it would echo value 1, value 3, value 5.
                         //in your case, it would echo whatever $row['Report ID'] is equivalent to.
    }
}
?>

Upvotes: 1

Related Questions