What is the potential issue with displaying an external image in PHP from a database?

The potential issue with displaying an external image in PHP from a database is that it can open up security vulnerabilities such as SQL injection or cross-site scripting attacks. To solve this issue, you should sanitize the input data to prevent any malicious code from being executed.

// Get the image URL from the database
$image_url = "https://example.com/image.jpg";

// Sanitize the image URL to prevent any malicious code execution
$sanitized_image_url = filter_var($image_url, FILTER_SANITIZE_URL);

// Display the image using the sanitized URL
echo '<img src="' . $sanitized_image_url . '" alt="Image">';