What are some common pitfalls when trying to display images based on a variable in PHP?

One common pitfall when trying to display images based on a variable in PHP is not properly concatenating the variable within the image source attribute. To solve this issue, you can concatenate the variable within the image source attribute using string interpolation or concatenation.

<?php
// Variable containing the image filename
$imageName = 'image1.jpg';

// Concatenate the variable within the image source attribute
echo '<img src="images/' . $imageName . '" alt="Image">';
?>