PHP If statement not working as I thought it should -


i'm trying set error checking on form, have following far:

 if (empty($fname)) {         $error = true;         $error_fname = "please fill in first name";     }else if (empty($lname)) {         $error = true;         $error_lname = "please fill in first name";      } 

and although in first if statement assigns string variable $error_fname is, second else if statement nothing, doesn't assign error variable.

any this?

if meet first condtion never throw second, don't use if else 2 if , put error in array otherwise might overwrite if both condition met

$error_lname = array(); if (empty($fname)) {     $error = true;     $error_lname[] = "please fill in first name"; } if (empty($lname)) {     $error = true;     $error_lname[] = "please fill in last name";  } 

if need 2 separate errors might use different variables

if (empty($fname)) {     $error = true;     $error_fname = "please fill in first name"; } if (empty($lname)) {     $error = true;     $error_lname = "please fill in last name";  } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -