I have a problem with getting results with an IF
condition where the data is in a database.
The data is checkbox-submitted data. If users check the checkbox, then the value is "yes." When users uncheck the checkbox, then the value is '' (empty).
Let's say that the checkbox data is : $checkbox
And I have conditional with PHP like the code below. I want to show the header of website based on the checkbox status using these conditions:
I tried this:
if ( $checkbox == 'yes' || $checkbox == XXX ) {
// show header
} else {
// don't show header
}
and like this:
if ( $checkbox == 'yes' || $checkbox = undefined ) {
// show header
} else {
// don't show header
}
but it still doesn't work as expected: when the $checkbox
is '', PHP reports that $checkbox is undefined too.
How can I check for condition (XXX) to check the data is not set before but if the $checkbox
is set, the condition will be different?
Maybe as simple as:
if (isset($_POST['yourCheckboxName']) && $_POST['yourCheckboxName'] == 'yes') {
// show header
} else {
// don't
}
Anyway, who's you $checkbox
?