i got a list of checkbox, when i checked the checkbox, it should insert the value into database. when i unchecked the checkbox then it should be delete data from database.
if i assign a value in checkbox then i only can get the checked checkbox value. if i using a hidden field then i can get all value of checkbox but then i dunno which 1 is check and which 1 is uncheck.
Anyone can help?
$num="3";
for($i=1;$i<10;$i++){
?>
<form name="form1" method="post" action="testcheckbox.php">
<input type="hidden" name="task" value="validatesn">
<input type="hidden" name="validate[]" value="<?php echo $i;?>">
<input type="checkbox" name="validate[]" <?php if($num==$i){ echo "checked=checked";} ?> />Serialno<?php echo $i."<br/>"; ?>
<?php
$i++;
}
?>
<input type="submit" name="submit" value="Validate" />
</form>
<?php
if($_REQUEST['task'] == 'validatesn'){
$valid=$_POST['validate'];
foreach($valid as $v){
echo $v; //show all checkbox values
//if checkbox= checked then insert value into database
//if untick the checked checkbox then delete data from database
}
}
?>