What are the security implications of not properly sanitizing and validating form input in PHP?

Not properly sanitizing and validating form input in PHP can lead to security vulnerabilities such as SQL injection, cross-site scripting (XSS), and other types of attacks. To mitigate these risks, it is crucial to sanitize and validate user input to ensure that only expected and safe data is processed by the application.

// Sanitize and validate form input
$username = htmlspecialchars($_POST['username']);
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);