What potential pitfalls should be avoided when using PHP for checking user bans in a chatroom?

One potential pitfall to avoid when using PHP for checking user bans in a chatroom is not properly sanitizing user input, which can lead to SQL injection attacks. To mitigate this risk, always use prepared statements when querying the database to prevent malicious code execution.

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

// Prepare a statement to check if a user is banned
$stmt = $pdo->prepare('SELECT * FROM bans WHERE user_id = :user_id');
$stmt->bindParam(':user_id', $user_id);
$stmt->execute();

// Fetch the results
$banned_user = $stmt->fetch();

// Check if the user is banned
if ($banned_user) {
    echo 'User is banned!';
} else {
    echo 'User is not banned.';
}