Is there a better way of doing this?
I have a simple form with 30 check boxes.
If they are not checked, as far as PHP is concerned they don’t exist (not set), so I am setting the value to 0 as I am updating a database directly below this code:
if(!isset($_POST['checkbox1'])) {
$_POST['checkbox1'] = '0';
}
if(!isset($_POST['checkbox2'])) {
$_POST['checkbox2'] = '0';
}
if(!isset($_POST['checkbox3'])) {
$_POST['checkbox3'] = '0';
}
If they are checked the value is 1 so that part is fine.
I tried playing around with this but to no avail:
foreach($_POST AS $key=>$value) {
if($value != '1') { $_POST[$key] = '0'; }
}
How about