prepare("SELECT id FROM users WHERE username = ? OR email = ?"); $stmt->execute([$username, $email]); if ($stmt->fetch()) { $error = "Username or Email already exists."; } else { $hash = password_hash($password, PASSWORD_DEFAULT); $stmt = $pdo->prepare("INSERT INTO users (username, email, password, role) VALUES (?, ?, ?, 'user')"); if ($stmt->execute([$username, $email, $hash])) { header('Location: login.php?registered=1'); exit; } else { $error = "Registration failed. Please try again."; } } } } ?>