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']; header('Location: dashboard.php'); exit; } else { header('Location: index.php?error=Invalid email or password'); exit; } } catch (PDOException $e) { // In a real app, log this error instead of showing it to the user die('Database error: ' . $e->getMessage()); } }