What are common pitfalls when using PHP for website design?

One common pitfall when using PHP for website design is not properly sanitizing user input, which can lead to security vulnerabilities such as SQL injection or cross-site scripting attacks. To solve this issue, always sanitize and validate user input before using it in your PHP code.

// Sanitize user input using the filter_var function
$clean_input = filter_var($_POST['user_input'], FILTER_SANITIZE_STRING);
```

Another common pitfall is not handling errors properly, which can make debugging difficult and lead to unexpected behavior on the website. To solve this, always use error handling techniques such as try-catch blocks or logging errors to a file.

```php
// Example of using try-catch block for error handling
try {
    // Code that may throw an exception
} catch (Exception $e) {
    // Handle the exception, e.g. log the error or display a user-friendly message
}
```

Lastly, not optimizing code for performance can lead to slow loading times and a poor user experience. To solve this, make use of PHP caching techniques, minimize database queries, and use efficient algorithms in your code.

```php
// Example of using PHP caching with memcached
$memcached = new Memcached();
$memcached->addServer('localhost', 11211);

$key = 'cached_data';
$data = $memcached->get($key);

if (!$data) {
    // Code to fetch data from database
    $data = 'data_from_database';

    $memcached->set($key, $data, 3600); // Cache data for 1 hour
}

echo $data;