prepare("SELECT id, username, password_hash FROM users WHERE username = ?"); $stmt->execute([$username]); $user = $stmt->fetch(); if ($user && password_verify($password, $user['password_hash'])) { $_SESSION['user_id'] = $user['id']; $_SESSION['username'] = $user['username']; header('Location: index.php'); exit; } else { $errors[] = 'Invalid username or password.'; } } catch (PDOException $e) { $errors[] = 'Database error. Please try again later.'; } } } require_once __DIR__ . '/includes/header.php'; ?>