I have a login function and I'd like to return a variable value if false:
function login($email, $password, $mysqli) {
[...]
// check if username exists
if ($stmt->num_rows == 1) {
// check
if ($db_password == $password) {
//check
} else {
// Invalid password
$error = '2';
return false;
} else {
// No user exists.
$error = '1';
return false;
And this is the process_login
// 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");
}
I'd like the function to return the value of error variable, but it's not working.
What's wrong??
Thanks!
return $error;.falsefrom your function if login fails.