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.

Recommended Answers

All 3 Replies

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} ";


    $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);

        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 )
    [6] => on
    [7] => on
7 => on Array ( [6] => on [7] => on )
    [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, learning, and sharing knowledge.