I have a form with several checkboxes. These boxes have one row each in a mysql db if checked. Now, I need to have a loop that build a query to delete all rows that is not checked. I tried the one below but the array is never populated... Any help is appreciated...
$chk_cab_1 = isset($_POST['chk_cab_1']) ?: 0;
$chk_cab_2 = isset($_POST['chk_cab_2']) ?: 0;
$chk_cab_3 = isset($_POST['chk_cab_3']) ?: 0;
$chk_cab_4 = isset($_POST['chk_cab_4']) ?: 0;
$chk_cab_5 = isset($_POST['chk_cab_5']) ?: 0;
$chk_cab_6 = isset($_POST['chk_cab_6']) ?: 0;
$chk_cab_7 = isset($_POST['chk_cab_7']) ?: 0;
$chk_cab_8 = isset($_POST['chk_cab_8']) ?: 0;
$chk_cab_9 = isset($_POST['chk_cab_9']) ?: 0;
$chk_cab_10 = isset($_POST['chk_cab_10']) ?: 0;
$chk_cab_11 = isset($_POST['chk_cab_11']) ?: 0;
$check_cab = array();
$del_cab_ids = array();
for($i = 1; $i<=$counter; $i++) {
$check_cab["chk_cab_$i"] = $chk_cab_$i;
if($check_cab["chk_cab_$i"] == 0) {
$del_cab_ids[] = $i;
}
}
$sql = "DELETE FROM mytable
WHERE first_id = $t_key
AND second_id IN ($del_cab_ids)";
<input name="chk_cab[5]" type="checkbox" value="1" />so that you get an array immediately.