prepare("SELECT * FROM users WHERE username = :input OR email = :input LIMIT 1"); $stmt->execute(['input' => $login_input]); $user = $stmt->fetch(); // Note: The 'password' column stores the hash if ($user && password_verify($password, $user['password'])) { // Login Success $_SESSION['user_id'] = $user['id']; $_SESSION['username'] = $user['username']; $_SESSION['role'] = $user['role']; // Redirect to the appropriate dashboard if ($user['role'] === 'admin') { header("Location: admin/index.php"); } else { header("Location: dashboard.php"); } exit(); } else { $errors[] = 'Invalid login credentials.'; } } catch (PDOException $e) { error_log("Database error: " . $e->getMessage()); $errors[] = "An internal error occurred. Please try again later."; } } } ?>