If I use isset() for a text input then I write it like this:
$newpass = (isset($_POST['newpass'])) ? $_POST['newpass'] : '';
Now if I have a drop down menu like below:
<select name="students">
<option value="">Please Select</option>
<option value="john">John Doe</option>
<option value="Mike">Mike Smith</option>
</select>
Then can I use the same type of isset as I have used for text input:
$studentsdrop = (isset($_POST['students'])) ? $_POST['students'] : '';
or is the isset different fro a drop down menu?
isset() checks to see if a variable exists and that it is not set to NULL. It is not related to HTML at all.
In your case:
As long as you knew that
studentswas going to be present you wouldn’t need this.The most common time isset() is used upon form submits, is determining a checkbox. For example if you submit a form that has a checkbox, and that checkbox was not checked, it would not be passed into the
$_POSTvariable. This is crucial to use:$checkbox_name = isset($_POST['checkbox_name']) ? $_POST['checkbox_name'] : '';In the case of a
selectthe$_POSTvariable will always return, even if it is empty.