prepare("SELECT * FROM users WHERE username = :username LIMIT 1"); $stmt->execute(['username' => $username]); $user = $stmt->fetch(); // Note: The 'password' column stores the hash if ($user && password_verify($password, $user['password'])) { if (isset($user['status']) && $user['status'] !== 'active') { // Kept specific status check logic if status column existed, but since schema is simple, this block is mostly for safety if schema evolves. // Current schema doesn't have status, but if it did, we'd check it. // The setup_project.php removed the status column from users table to fit the simple requirements. // So we proceed. } $_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."; } } } ?>