What are some potential pitfalls when working with PHP code that may lead to errors on a website?

One potential pitfall when working with PHP code is not properly sanitizing user input, which can leave your website vulnerable to security risks such as SQL injection attacks. To prevent this, always validate and sanitize user input before using it in database queries or other sensitive operations.

// Example of sanitizing user input using mysqli_real_escape_string
$user_input = $_POST['user_input'];
$clean_input = mysqli_real_escape_string($connection, $user_input);
```

Another common mistake is not handling errors properly, which can lead to unexpected behavior or crashes on your website. Always use error handling techniques such as try-catch blocks or error_reporting to catch and handle any potential errors in your PHP code.

```php
// Example of using try-catch block for error handling
try {
    // code that may throw an exception
} catch (Exception $e) {
    // handle the exception
    echo 'An error occurred: ' . $e->getMessage();
}
```

Lastly, not properly managing resources such as database connections or file handles can lead to memory leaks and performance issues on your website. Always close connections and release resources when they are no longer needed to ensure optimal performance.

```php
// Example of closing a database connection
mysqli_close($connection);