What are some common pitfalls to avoid when sharing code snippets or solutions in PHP forums, and how can constructive feedback be provided to improve code quality?

Issue: One common pitfall when sharing code snippets in PHP forums is not properly sanitizing user input, which can lead to security vulnerabilities such as SQL injection attacks. To avoid this, always use prepared statements or input validation functions to sanitize user input before using it in database queries. Solution:

// Example of using prepared statements to sanitize user input
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->bindParam(':username', $_POST['username']);
$stmt->execute();
$user = $stmt->fetch();