php - Undefined variable of print_r -


i got code in php: purpose of $errors display error when execute them in php. sadly says $errors not defined variable.. how come? me please?

if (empty($username) === true || empty($password) === true) {     $errors[] = 'you need enter username , password'; }  else {     //here }  print_r ($errors); 

}

and got error..

notice: undefined variable: error in c:\xampp\htdocs\shaven\login.php on line 28 

may know how solved this?

if $username and $password isn't empty, code inside if block won't executed , $errors won't defined. in case, you'll trying print_r() undefined variable.

initialize $errors empty array before doing comparison:

$errors = array(); 

and before doing print_r(), make sure array isn't empty:

if (!empty($errors)) {     print_r($errors); } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -