Skip to content Skip to sidebar Skip to footer

Displaying An Image Using A Php Variable

I'm trying to display images by taking their file path from an sql table, but i'm having a lot of troubles. Here is whats going on: $image is a variable containing the text 'itemim

Solution 1:

First of all, you should not use PHP Shorttags.

When you use the PHP Shorttags you have to say:

<imgsrc="<?=$image?>"alt="test" />

But i would encourage to escape the Content off the variable like this:

<imgsrc="<?phpecho htmlspecialchars($image); ?>"alt="test" />

Your extra question:

This should lead to an syntax error because the string could not be parsed, just use $image = $row['image'];

Solution 2:

Try this

<img src= "<?php echo $image ?>" alt="test"/>

Solution 3:

try

<imgsrc= "<?=$image?>"alt="test"/>

or

<imgsrc= "<?echo$image; ?>"alt="test"/>

Solution 4:

try this

<imgsrc= "<?phpecho$image?>"alt="test"/>

Post a Comment for "Displaying An Image Using A Php Variable"