What are the potential pitfalls of using a quick and dirty approach to displaying data in PHP, as seen in the provided code snippets?

Using a quick and dirty approach to displaying data in PHP can lead to security vulnerabilities such as SQL injection attacks or cross-site scripting (XSS) attacks. To prevent these risks, it is essential to properly sanitize and validate user input before displaying it on a web page.

// Example of properly sanitizing user input before displaying it
$userInput = $_POST['user_input'];

// Sanitize the user input using htmlspecialchars to prevent XSS attacks
$sanitizedInput = htmlspecialchars($userInput);

// Display the sanitized input
echo $sanitizedInput;