prepare("SELECT * FROM users WHERE email = ?"); $stmt->execute([$email]); $user = $stmt->fetch(); if ($user && password_verify($password, $user['password'])) { $_SESSION['user_id'] = $user['id']; $_SESSION['user_name'] = $user['name']; $_SESSION['user_role'] = $user['role']; if ($user['role'] === 'owner') { header('Location: dashboard_owner.php'); } else { header('Location: dashboard_client.php'); } exit(); } else { header('Location: index.php?error=Invalid email or password.'); exit(); } } catch (PDOException $e) { // In a real app, you would log this error. header('Location: index.php?error=An internal error occurred.'); exit(); } } else { header('Location: login.php'); exit(); }