I try to login with a new created user. But when I try to login it throw’s the error message.
So This is the login:
public function login()
{
// Check for POST
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo ('hello');
// Process form
// Sanitize POST data
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
// Init data
$data = [
'email' => trim($_POST['email']),
'password' => trim($_POST['password']),
'email_err' => '',
'password_err' => '',
];
// Validate Email
if (empty($data['email'])) {
$data['email_err'] = 'Pleae enter email';
}
// Validate Password
if (empty($data['password'])) {
$data['password_err'] = 'Please enter password';
}
// Check for user/email
if ($this->userModel->findUserByEmail($data['email'])) {
// User found
} else {
// User not found
$data['email_err'] = 'No user found';
}
// Make sure errors are empty
if (empty($data['email_err']) && empty($data['password_err'])) {
// Validated
// Check and set logged in user
$loggedInUser = $this->userModel->login($data['email'], $data['password']);
if ($loggedInUser) {
echo $data['password'];
echo $data['email'];
// Create Session
$this->createUserSession($loggedInUser);
} else {
$data['password_err'] = 'Password incorrect';
$this->view('users/login', $data);
}
} else {
// Load view with errors
$this->view('users/login', $data);
}
} else {
// Init data
$data = [
'email' => '',
'password' => '',
'email_err' => '',
'password_err' => '',
];
// Load view
$this->view('users/login', $data);
}
}
and so it doesn’t reach the two echo messages.
But I can’t figure out why I can’t login.
and the new created user is appearing in the database.