What are some potential pitfalls to be aware of when using PHP to extract and display data from a database?

One potential pitfall when using PHP to extract and display data from a database is SQL injection attacks. To prevent this, it is important to sanitize user input before using it in SQL queries. This can be done using prepared statements or parameterized queries in PHP.

// Using prepared statements to prevent SQL injection
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();
```

Another potential pitfall is not properly handling errors that may occur during database queries. It is important to check for errors and handle them gracefully to prevent exposing sensitive information or crashing the application.

```php
// Checking for errors in database queries
if(!$stmt) {
    die("Error executing query: " . $pdo->errorInfo()[2]);
}
```

Lastly, be cautious of displaying sensitive data to users without proper authorization. Always validate user permissions before displaying certain data to ensure data security and privacy.

```php
// Checking user permissions before displaying sensitive data
if($user->isAdmin()) {
    echo $sensitiveData;
}