prepare("SELECT * FROM users WHERE username = :username OR email = :email"); $stmt->execute(['username' => $username, 'email' => $email]); if ($stmt->fetch()) { $error = 'Username or email already exists.'; } else { // Insert new user $hashed_password = password_hash($password, PASSWORD_DEFAULT); $insert_stmt = $pdo->prepare("INSERT INTO users (username, email, password) VALUES (:username, :email, :password)"); $insert_stmt->execute([ 'username' => $username, 'email' => $email, 'password' => $hashed_password ]); header("Location: login.php?registered=true"); exit; } } catch (PDOException $e) { $error = "Database error: " . $e->getMessage(); } } } ?>