I'm watching a video tutorial where the instructor is testing a form submission.
The code he is using is:
$required_fields = array('menu_name', 'position', 'visible');
foreach ($required_fields as $fieldname) {
if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0) {
$errors[] = $fieldname;
}
}
Notice the condition in the if statement
after the &&
where he has $_POST[$fieldname] != 0
This does not work for me for some reason.
However, when I give the 0
quotes like this $_POST[$fieldname] != "0"
then it works.
BTW, the 'visible'
field is a boolean, aka tinyint(1)
, in MySQL.
Here is what the HTML on the form looks like for this field:
Visible:
<input type="radio" name="visible" value="1" <?php if ($sel_subject['visible'] == "1") {echo "checked=\"checked\"";} ?> /> Yes
<input type="radio" name="visible" value="0" <?php if ($sel_subject['visible'] == "0") {echo "checked=\"checked\"";} ?> /> No
Any ideas? Thank you in advance for your help.
UPDATE:
I'm not sure what happened, but for some reason the code is working now without the quotes. Sorry for any confusion.