So I'm trying to display images from a database for a website that I'm building for a friend. He wants to be able to upload an image, and have it display on the front page.
I have the image uploading all working. Saving it in the database as a BLOB.
I began working on displaying the images on a separate file. I got it working on my test website, images displayed how he wanted them. But then I moved the code over to the actual website, got it to how it needed to be and it didn't work.
I ended up trying it again on my test website, and it all worked fine.
For some, it isn't working on the actual website, but it's working fine on my test website.
The actual website grabs more information the my test website does.
Here is the code the I've used on my test website.
image.php
$query = mysql_query("SELECT * FROM images LIMIT 1");
while($row = mysql_fetch_assoc($query)){
$image_id = $row['id'];
echo "<img src=showimage.php?id=".$image_id.">";
}
Here is how I'm grabbing the image from the database and displaying it.
showimage.php
include 'inc/db.php';
$id = addslashes($_REQUEST['id']);
$image = mysql_query("SELECT image FROM sites WHERE id = '$id'");
$image = mysql_fetch_assoc($image);
$image = $image['image'];
header("Content-type: image/png");
echo $image;
Using that code on the test website works fine, there's no problem there.
Here is my code for the actual website.
sites.php
$select = mysql_query("SELECT * FROM sites");
while($row = mysql_fetch_assoc($select)){
$image_id = $row['id'];
echo '
<tr class="bottom"><td>'.$row['host'].'</td>
<td>'.$row['currency'].''.$row['price'].' every '.$row['payment'].'</td>
<td>'.$row['domain'].'</td>
<td>'.$row['paid_currency'].''.$row['paid_domain'].'</td>
<td>'.$row['features'].'</td>
<td>
<span title="Edit '.$row['id'].'"><a href="edit.php?id='.$row['id'].'"><img src="images/edit.png" alt="Edit"></a></span>
<span title="Delete '.$row['id'].'"><a href="inc/delete.php?id='.$row['id'].'"><img src="images/delete.png" alt="Delete"></a></span>
</td>
<td><img src=showimage.php?id='.$image_id.'></td></tr>
';
}
That using the showimage.php file to grab the image from the database, but isn't working at all.
imageinsitestable?srcattribute is missing quotations. Also, do not use GET requests for modifying (i.e., deleting) data.