Displaying image from MySQL other than echoing
Displaying image from MySQL other than echoing
Is there another way to put image from MySQL to html other than echoing it like this:
echo "<img src='images/" . $row['event_image'] . "' height='200' width='320' class=responsivez> ";
Im trying to put the image path onto the html tag. The getImage.php displays my image path but when called on the next page the image doesnt display. Am i missing some important syntax?
<img src="images/getImage.php?" width="175" height="200" />
getImage.php
<?php
$con=mysqli_connect("localhost","root","","blast");
if (!$con)
die("Connection failed: " . mysqli_connect_error());
$state='Johor';
$result=mysqli_query($con,"SELECT * from blast_events where
event_state='$state'");
if (!$result)
die ('SQL Error: ' . mysqli_error($con));
else
$row=mysqli_fetch_array($result);
echo $row["event_image"];
?>
src
You're going about this in the exact right way (aside from parameterisation); echoing out an
<img>
tag. Having said that, $row['event_image']
shouldn't give you getImage.php?
. Is that in your table row? You should be storing something like image001.png
. Then your <img>
tag will map out correctly (assuming the relevant image is on the server).– Obsidian Age
49 mins ago
<img>
$row['event_image']
getImage.php?
image001.png
<img>
1 Answer
1
Try to Output the image instead of just a path:
header('Content-Type:image/jpeg');
readfile($row["event_image"]); // make sure the path is valid not only filename.
// echo $row["event_image"];
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Do cmd+u (on Mac) or ctrl+u (on Windows), and see if the link in the
src
attribute is correct or not.– Rajdeep Paul
50 mins ago