Are there any potential pitfalls when manipulating URL query strings in PHP?

One potential pitfall when manipulating URL query strings in PHP is the risk of SQL injection attacks if the input is not properly sanitized. To solve this issue, always use prepared statements or parameterized queries when interacting with a database to prevent malicious SQL injection.

// Example of using prepared statements to prevent SQL injection
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->bindParam(':username', $_GET['username']);
$stmt->execute();
$result = $stmt->fetchAll();