What are the potential pitfalls of using innerHTML and onClick attributes in PHP code?

Using innerHTML and onClick attributes in PHP code can potentially lead to security vulnerabilities such as cross-site scripting (XSS) attacks. To mitigate this risk, it is recommended to properly sanitize user input and escape output to prevent malicious code injection.

<?php
// Sanitize user input
$user_input = htmlspecialchars($_POST['user_input']);

// Output sanitized input
echo "<div onClick='someFunction()'>" . $user_input . "</div>";
?>