What are the security implications of not properly escaping user input in PHP code?

Not properly escaping user input in PHP code can lead to security vulnerabilities such as SQL injection, cross-site scripting (XSS), and other forms of attacks. To mitigate these risks, it is crucial to sanitize and validate user input before using it in your code.

$user_input = $_POST['user_input'];
$escaped_input = htmlspecialchars($user_input, ENT_QUOTES, 'UTF-8');
// Now use $escaped_input in your code to prevent XSS attacks