I want to select multiple rows from checkbox and want to update them all at once by button click..I tried in several ways..but not work..can you give a help please? it shows an error as Undefined index: checkbox
<td>
<input type="hidden" name="id" id="id" value="<?php echo $row["file_serial_id"]; ?>" />
<input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $row['file_serial_id']?>" />
</td>
if(isset($_POST['send_btn']) and $_POST['send_btn']=="Send"){
$checkbox = $_POST['checkbox']; //from name="checkbox[]"
$countCheck = count($_POST['checkbox']);
for($i=0;$i<$countCheck;$i++){
$del_id = $checkbox[$i];
$sql2 = "UPDATE retained_file_mst SET mark_to_dispose=1 WHERE file_serial_id='$del_id'";
$result2 = mysql_query($sql2,$conn);
}
// if successful redirect to delete_multiple.php
if($result2){
echo "success";
}else{
echo "error";
}
}
You can access your checkboxes like so:
This allows you to set it to the correct value if the user entered it and set it to 0 if the user did not check it.
Another alternative would be to set it 0 which may be more space conservative for things like databases.
Edit
Since you are actually using it as an array this would be better:
Or just doing a quick
ifto see if the $checkbox is an array:P.S Use code formatting if you want people to understand your question. I have done it for you this time