What are potential security risks associated with not properly escaping user input in PHP code?

When user input is not properly escaped in PHP code, it can lead to security vulnerabilities such as SQL injection, cross-site scripting (XSS), and command injection. To mitigate these risks, it is important to sanitize and escape user input before using it in SQL queries, HTML output, or shell commands.

$userInput = $_POST['input'];
$escapedInput = htmlspecialchars($userInput, ENT_QUOTES, 'UTF-8');
echo "Escaped input: " . $escapedInput;