View image

Greetings!

I heard that it’s not a good practice to save the image itself in the database, so I did is to save the file name and it’s size at the same time, the actual image will save in a folder I call ‘images’, and I did it working. The problem is the image is not working properly when showing, the result is a torn paper icon.

below are my codes.


$show  = mysql_query ("SELECT  MAX(id) AS mid FROM upload ") or die (mysql_error());
				while ($row=mysql_fetch_array ($show))
				{
				echo $row['mid']."<br/>";
				echo "<img src = 'images/".$row['mid'].">";

I tried to get the source code to display the name that matched in my query.
Any help would be appreciated.

From the query, it looks like you’re selecting an ID, not a filename. I think you need to rethink your query.

thank you for your quick response. I change already, I can see now my filename, but still I got the same icon.

$show  = mysql_query ("SELECT  name FROM upload ") or die (mysql_error());
				while ($row=mysql_fetch_array ($show))
				{
				echo $row['name']."<br/>";
				echo "<img src = 'images/".$row['name'].">";
				
				}

There’s an error in your HTML output (the image tag is incorrect, too many spaces in the src attribute and you’re missing a closing quote), try this:


$show  = mysql_query ("SELECT  name FROM upload ") or die (mysql_error());
while ($row=mysql_fetch_array ($show))
{
    echo $row['name']."<br/>";
    echo '<img src="images/'.$row['name'].'">';
}

Having spaces in the src attribute is not an issue.

This works fine, although I wouldn’t normally have the additional spaces.

<img src = "pic1.jpg" alt="" />

@OP

you can normally fix problems like in your post fairly quickly by looking at the actual html created by your php code. Run your php page in your browser and select ‘View source’ (or whatever your browser has) to see the actual html created by your php code. Then scroll to the problem area in your html to see what the problem is. Then fix your php code so that it creates the correct html.

thank you. I got it working already…