What are the potential security risks associated with not properly sanitizing user input in PHP, and how can they be mitigated?

When user input is not properly sanitized in PHP, it can lead to security vulnerabilities such as SQL injection, cross-site scripting (XSS), and command injection. To mitigate these risks, always validate and sanitize user input before using it in database queries, outputting it to the browser, or executing system commands.

// Example of sanitizing user input in PHP
$user_input = $_POST['input'];
$clean_input = filter_var($user_input, FILTER_SANITIZE_STRING);