CODE:
<input type="checkbox" name="discountedItem" <?php if (isset($_POST['discountedItem'])) echo "checked" . " " . "value='y'"; ?> />
How can I transform this into an if statement so that if it’s not checked the value is n?
I tried:
<input type="checkbox" name="discountedItem" <?php if (isset($_POST['discountedItem'])) { echo "checked" . " " . "value='y'"; } else { echo "value='n'"; } ?> />
Didn’t work. The value was just NULL.
The
value=is never submitted if the checkbox isn’t set.You can’t have your
nwith a checkbox. Consider a radio button. Or simply adapt your processing logic (theifyou referred to) not to look for strings, but any present value.