0

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

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by ckchaudhary
0

why dont you just add an if statement

$del_id = $checkbox[$i];
if($del_id !=0)
{
    /*your db operation*/
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.