Why does my isset()
function return true when the value from the select option in the HTML form is set to =""
which I was expecting to be NULL
and the isset()
function should return FALSE ?
This is the HTML select option:
<select name="filler">
<option value="">Select Transfer</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
Inside this isset function i've added a JS alert and this alert is triggered
if(isset($_POST['filler'])) {
?>
<script>
alert("filler item in post");
</script>
....other PHP code runs here....
}
CodePudding user response:
CodePudding user response:
isset() is used to check if the variable is set with the value or not
and after isset you can also check empty
Empty() is used to check if a given variable is empty or not. isset() returns true when the variable is not null whereas Empty() returns true if the variable is an empty string.
CodePudding user response:
use this:
$option = isset($_POST['filler']) ? $_POST['filler'] : false;