Hi guys

I am after a pre written PHP script or a tutorial which displays records from a table each with a checkbox. ( I have worked to this part)

When the check box is ticked and the submit button is pressed, the records with a checkbox get inserted into another table.

Any tutorial or script or webpage to guide me would be greatly appreciated.

I am not a coder but can study scripts and adapt and apply to my personal projects.

Thank you, using a mish mash of tutorials, I have an almost 90% working solution.

Problem: When the checkboxes are selected, all records (unchecked) ones are also inserted.

My HTML file has a drop down value and a checkbox:

<input type="checkbox" name="checkbox[<?php echo $row['user_id']; ?>]">

My PHP file:

$checkbox = $_POST['checkbox'];
$class_id = trim($_POST['class_id']);



foreach ($checkbox as $key => $value) {
      echo "{$key} => {$value} ";


    //print_r($checkbox);

    $sql = "INSERT INTO Class_List (user_id,class_id) VALUES (?, ?)";

    if($stmt = mysqli_prepare($link, $sql)){

        mysqli_stmt_bind_param($stmt, "ii", $value, $class_id);


    if(mysqli_stmt_execute($stmt)){
        echo "";

    } else{
        echo "ERROR in inserting records: $sql. " . mysqli_error($link);

When I print the Checkbox Array I get:

6 => on Array ( [6] => on [7] => on )
Array
(
    [6] => on
    [7] => on
)
7 => on Array ( [6] => on [7] => on )
Array
(
    [6] => on
    [7] => on
)
The selected students have been added

I have not worked with Arrays so not sure what this output means.

Any helpp will be greatly appreciated,

I'm curious what the output looks like if you were to do print_r($checkbox); on line 3 of your PHP file, immediately after setting the value of $checkbox to what's in POST (above your foreach loop).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.