I’m trying to display images and relevant data based on what the user enters in a form(IMG 1). Everything is working but I need the table to show the actual image instead of URL.
In my database, I’ve got the image data stored as URL but I want to show as an image on the PHP page (IMG 3).
So in the table (IMG 2), I want the actual image to show up instead of link
Here is the most important part of the code that does the searching and displays the data.
$title = trim($_POST["PhotoTitle"]);
$FromDate = trim($_POST["FromDate"]);
$ToDate = trim($_POST["ToDate"]);
$keywords = trim($_POST["keywords"]);
$query ="SELECT * FROM `photos` WHERE `Photo-Title` like '%".$title."%' AND `Keywords` like '%".$keywords."%' AND `Date-of-Photo` BETWEEN '$FromDate' AND '$ToDate'";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>n ";
echo "<td>",$row["Photo-Title"],"</td>n";
echo "<td>",$row["Description"],"</td>n";
echo "<td>",$row["Date-of-Photo"],"</td>n";
echo "<td>",$row["Keywords"],"</td>n";
echo "<td>",$row["Reference-to-S3"],"</td>n";
echo "</tr>n ";
}
I can provide any other information if needed.
How do I solve this problem?
2
Answers
First: Your code is highly insecure. It is vulnerable to sql injections and XSS.
Regarding your Question: You need to output an html tag with the image url as the src attribute.
Like this:
Just edit your while to this piece of code :
what it does is displaying a URL as an image using
<img />
tag of HTML. Also,alt
adds a title to the image which if you hover image, you can see the value of this attribute.