Why i cannot add a php file inside of imgsrc

Hello there i have made a saperate file to display images with reference of ID and i want to insert into another file inside of imgsrc"". I have tried it a lot but not getting the image so give me solution for this.

So what have you tried? If you don’t give us anything to feed on what are we supposed to say (except “it works for me”)?

<img src="<?php include 'fetchimage.php';?>;
i Have tried this

<img src="fetchimage.php" alt="dynamic image">

Assuming that fetchimage.php returns binary image data with the correct MIME header.

And what’s the result in your browser? Check also the html code

The result is it shows only a empty box insted of image.

@amitkanjiyani3398 You absolutely need to do this! If the browser cannot read the image data you only see the mentioned empty box. But it tells you naught what’s going on.

See there if i insert an name of image inside of imgsrc"abc.jpg" it works fine and it displays the image correctly. And i want to prepare a dashboard where every user creates its own profile and i have called image with reference to id from database.

What about the resulting html? View source.

see post #4

what are you trying to say Dormilich cant understand

What is in fetchimage.php?

Fetch image is the php file from which i am fetching image from the database which is uplaoded in my root folder too…

$con = mysql_connect('localhost','root',''); 
if (!$con) { die('Could not connect: ' . mysql_error()); } 
mysql_select_db("job", $con); 
$result = mysql_query("SELECT file FROM describepost WHERE id='22'"); 
echo "<table border='1' width='100%' >"; 
    while($row = mysql_fetch_array($result)) { 
        echo "<tr>";
              echo "<td>" . $row['file'] . "</td>";
        echo "<td><img src='img/".$row['file']."'></td>";
        echo "</tr>"; 
echo "</table>";


So you are echoing a table into the src attribute of the img?

Do I need to say what’s wrong with that?

I stab a guess at ‘yes’.

1 Like

See there let me explain you the whole concept. I am trying to make an dashboard for the uses with their uploaded images and i would like to fetch tt from the database and the uploaded image is inserted inside of the root folder too.
Say formfetch.php is the file from where the image is fetched from the database with reference of the id for example id=“22” and if i am running the formfetch.php alone it works but if i am including it inside of profile part it is not working…

That’s because HTML is not at all the same as an image. Browsers can display HTML and they can display images. But images themselves (as represented by <img> tags) can only display binary image data and only when the image’s MIME headers are correct.

Is there any of the other solution for this?

The answer is in just basic html.
If you have an img element, its src attribute will generally contain a url for an image file.
You are trying to inset an html table into the src attribute, which is wrong for very obvious reasons.
If you look at the resulting html code (as you were asked to) this would all be obvious.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.