hi all im having a issue with non selected checkboxes
when i select checkboxes and hit submit they go into the database ok but the checkboxes that have not been selected are adding 0 to the database

code below:

<form action="addeventusers.php?evid=<?php echo $evid; ?>&u=<?php echo $u; ?>" method="post">
user 1 <input type="checkbox" name="user[]" id="user[]" value="'.$userid.'" />
user 2 <input type="checkbox" name="user[]" id="user[]" value="'.$userid.'" />
<input type="submit" name="submit" id="submit" value="submit" />
</form>

php submission:

<?php
if(isset($_POST['submit'])){
    $checkbox = $_POST['user'];
    $submit = $_POST['submit'];
    if($submit){
                for($i=0;$i<$count;$i++){
                    $del_id = $checkbox[$i];
                    $sql = "INSERT INTO ev_invites (event_id, userid) VALUES ('$evid', '$del_id')";
                    $result = mysql_query($sql);
                    }
                    if ($result) {
                        echo "done";
                        }
                        mysql_close();
    }
}
?>

basically what i am looking for is a way to stop the non selected checkbox from inserting into the database

why dont you just add an if statement

$del_id = $checkbox[$i];
if($del_id !=0)
{
    /*your db operation*/
}
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.