sayedsohail Posted July 3, 2007 Share Posted July 3, 2007 Hi everyone, the code below only display first occurance of false error message, infact i am sending both the email and password value in incorrect format of regexp. So it should display both the errors when the functions are called. Any help is greaty appreciated. thanks, <?php //declare variable $outdata=""; // Ist function function validate_email($email) { $regexp = "^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$"; // validating the syntax of email if (!eregi($regexp, $email)) { global $outdata; $outdata.= "Email contains illegal characters, Please use a valid email address."; return false; } else {return true;} } //IInd function function validate_password($password) { $regexp = "^([a-zA-Z0-9]{6,20})$"; // validating the syntax of password if (!eregi($regexp, $password)) { global $outdata; $outdata.= "Password contains illegal characters, Please user letter, numbers only"; return false; } else {return true;} } if (validate_email($email) && validate_password($password)) { //do something... } echo $outdata; ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 3, 2007 Share Posted July 3, 2007 Edit: Scrap that, 'twas wrong Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 3, 2007 Share Posted July 3, 2007 Ah, i've finally got it - this was really annoying me. Once the first function in your if statement returns false, php doesn't bother to evaluate the second part of it(and therefore the function does not run) - obviously it would be a waste of processing power since it has already found out that the if statement will overall be false. What you'll have to do, is fun the two functions and store the output into variables: <?php $email_success = validate_email($email); $password_success = validate_password($password); if($email_success === true && $password_success === true){ //both true }else{ //one or more false } ?> Quote Link to comment Share on other sites More sharing options...
sayedsohail Posted July 3, 2007 Author Share Posted July 3, 2007 Mr. ben, now even if one function is false, it prints two errors' one of email and the other of password. It seems the conflict of defining global. Any idea? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.