I have a form with multiple radio buttons, they all seem to work fine until i try to do error handling.
CODE HTML:
<form action="" method="POST">
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female
<input type="submit" value="Submit">
</form>
php:
if (strip_tags(trim(isset($_POST['gender']))) == NULL) {
$error[] = ' Error: please select male or female ';
} else { //if it is set then $uGender should hold post value
$uGender = strip_tags(trim($_POST['gender']));
}
I tried to catch if the radio button male
or female have been set using
isset()` when I try to use it pushes out undefined variable or undefined index. It will still post without having any value which leads to a SQL error as the Gender field by default cannot be a NULL value.
Another issue: it posts everything to the database and leaves the gender field empty even though there is an error handler?