Search code examples
phpsqlcheckboxinbox

Inbox-System Checkboxes To Select Messages


We currently are implementing an inbox system into our website and want a user to be able to checkmark multiple inbox messages and click a Delete link to mass-delete them.

Each inbox message has it's own ID in the database.

What we need help with is getting the checkbox system working. We don't know where to start with it; whether we have to give each one an ID or fill in some value with PHP - we just don't know. Any help is greatly appreciated.


Solution

  • The xHTML form

    <input type="checkbox" name="record[]" value="1" />
    <input type="checkbox" name="record[]" value="2" />
    <input type="checkbox" name="record[]" value="3" />
    <input type="checkbox" name="record[]" value="4" />
    

    The PHP

    <?php
    
    foreach ($_POST['record'] AS $id) {
    
        $id = (int)$id; // Force to integer (little of security)
    
        // Delete the record
        mysql_query("DELETE FROM `table` WHERE `id` = {$id}");
    
    }
    
    ?>