What are some common pitfalls to avoid when writing PHP queries for database manipulation?

One common pitfall to avoid when writing PHP queries for database manipulation is SQL injection vulnerabilities. To prevent this, always use prepared statements with parameterized queries to sanitize user input and prevent malicious SQL injection attacks. Example:

// Connect to database
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');

// Prepare a SQL statement with a parameterized query
$stmt = $pdo->prepare('INSERT INTO users (username, email) VALUES (:username, :email)');

// Bind parameters
$stmt->bindParam(':username', $username);
$stmt->bindParam(':email', $email);

// Set the parameters and execute the query
$username = 'john_doe';
$email = 'john.doe@example.com';
$stmt->execute();