title: php function return false and $variable value not working
body: <p>I have a login function and I'd like to return a variable value if false:</p>
  
  <pre><code>function login($email, $password, $mysqli) {
  [...]
  // check if username exists
  if ($stmt-&gt;num_rows == 1) {
      // check
  if ($db_password == $password) {
      //check
  } else {
      // Invalid password
      $error = '2';
      return false;
  } else {
          // No user exists.
          $error = '1';
          return false;
  </code></pre>
  
  <p>And this is the process_login</p>
  
  <pre><code>// the login function is included in this page
  if (login($email, $password, $mysqli) == true) {
      // Login success
      header('Location: /index.php');
  } else {
      // Login failed
      header("Location: /login.php?error=$error");
  }
  </code></pre>
  
  <p>I'd like the function to return the value of error variable, but it's not working.</p>
  
  <p>What's wrong??</p>
  
  <p>Thanks!</p>