I am trying to do form validation but when I try to print out the contents of an array when there is an error it doesnt output anything.
$errors = array();
if (strlen($password) >= 6) {
array_push($errors, "Your password is not long enough! Must be over 6 characters!");
}
if(count($errors) !== 0) {
...
} else {
echo "There is errors<br/>";
foreach($errors as $er){
echo $er . "<br/>";
}
}
What I do get is “There is errors” so I know that the if else is working.
I just have to correct the argument of the
if:In this way, when your error count is 0, the content of the
ifis executed. When it isn’t 0, the content of theelseis executed and the errors are printed. It’s just the opposite of what you did.(I also corrected the sentence: it’s ‘there are errors’, not ‘there is errors’ :P)
Furthermore, the other
ifis wrong as well, it should be the opposite:since you need to check when the password is less than 6 characters.