<label>Gender<span class="note">*</span>:</label>
<select name="gender">
<option value="1" selected <?= ($_POST['gender'] == "1")? "selected":"";?>>Select</option>
<option value="male" <?= ($_POST['gender'] == "2")? "selected":"";?>>Male</option>
<option value="female" <?= ($_POST['gender'] == "3")? "selected":"";?>>Female</option>
</select>
<?php echo "<p class='note'>".$msg_gender."</p>";?>
if (isset($_POST['submit'])) {
$gender = $_POST['gender'];
if($gender != "2" || $gender != "3"){
$msg_gender = "Gender not valid";
}
}
If the $msg_gender="" the form will be valid, else it’ll say gender invalid. But it says gender invalid at every stage no matter which option i select
3
Answers
Your value is not 3 or 2 but ‘male’ or ‘female’ so you must change your condition to
Or change your option values
change your code to this:
the option value is what is actually being sent