prepare("SELECT * FROM users WHERE username = ?"); $stmt->execute([$username]); $user = $stmt->fetch(); if ($user && password_verify($password, $user['password_hash'])) { $_SESSION['user_id'] = $user['id']; header('Location: index.php'); exit; } else { $error = 'Invalid username or password.'; } } catch (Exception $e) { $error = 'Login failed.'; } } } ?>