What are common issues with outputting data from a database in PHP?
One common issue when outputting data from a database in PHP is not properly handling special characters, which can lead to display issues or security vulnerabilities. To solve this problem, you can use the htmlspecialchars function to escape special characters before outputting the data.
<?php
// Retrieve data from database
$data = "<script>alert('Hello!');</script>";
// Output data with htmlspecialchars to escape special characters
echo htmlspecialchars($data);
?>