What are the security implications of not properly handling special characters in passwords in PHP applications?

Not properly handling special characters in passwords in PHP applications can lead to vulnerabilities such as SQL injection or cross-site scripting attacks. To mitigate this risk, it is important to properly sanitize and escape special characters in passwords before storing them in a database or using them in SQL queries.

$password = $_POST['password'];
$escaped_password = mysqli_real_escape_string($conn, $password);