I have a $name
variable containing a string, and when I test it, I never get the "Name should be between 2 and 40 characters" error even when it's less than 2 characters long or more than 40. Why?
if (strlen($name) < 2 && strlen($name) > 40) {
$nameError = 'Name should be between 2 and 40 characters';
}
T.J. Crowder
How can the length be less than 2 and greater than 40? You want ||
("or"), not &&
("and").
if (strlen($name) < 2 || strlen($name) > 40) {
// -------------------^^
来源:https://stackoverflow.com/questions/42190142/whats-wrong-with-my-if-else-statement