I have a form that validates First Name, Last Name, and E-mail before processing. It seems however that something isn't working. If I enter an e-mail address and my script validates it, then the page continues regardless of the checks I have in place for First and Last Name.
HTML Form Inputs
First Name <input type="text" id="new_user_fn" name="new_user_fn">
Last Name <input type="text" id="new_user_ln" name="new_user_ln">
PHP Script
$ec = 0;
$fn = trim($_POST['new_user_fn']);
$ln = trim($_POST['new_user_ln']);
if(!ctype_alpha($fn) OR strlen($fn) <= 0){
$error = "First Name cannot be blank and may only contain letters";
$ec++;
}
if(!ctype_alpha($ln) OR strlen($ln) <= 0){
$error = "Last Name cannot be blank and may only contain letters";
$ec++;
}
Essentially this checks if the $fn is alphabetic and greater than 0 in length to ensure the user filled out the input with valid text. I go on to verify the e-mail address (this part works correctly so it has been omitted from the post) and check the value of $ec.
if($ec > 0){
die($error);
}else{
// Finish Processing
}
So if I leave the inputs for "fn" and "ln" blank but supply a valid e-mail address, the script still executes as if $ec = 0.
Am I missing something simple?
Lukas found the issue above. Another $ec = 0 existed that was not commented out. Removing it solved the problem. Thanks all. Always nice to have an extra set of eyes sometimes. Much appreciated!