What potential security risks are associated with user input in PHP scripts, and how can they be mitigated?

Potential security risks associated with user input in PHP scripts include SQL injection, cross-site scripting (XSS), and file inclusion vulnerabilities. These risks can be mitigated by properly sanitizing and validating user input, using parameterized queries for database interactions, and escaping output to prevent XSS attacks.

// Example of mitigating SQL injection by using parameterized queries
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $_POST['username']);
$stmt->execute();
```
```php
// Example of mitigating XSS by escaping output
echo htmlspecialchars($_POST['input']);