title: PHP display images from database
body: <p>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.</p>
  
  <p>I have the image uploading all working. Saving it in the database as a BLOB. </p>
  
  <p>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.</p>
  
  <p>I ended up trying it again on my test website, and it all worked fine.</p>
  
  <p>For some, it isn't working on the actual website, but it's working fine on my test website.</p>
  
  <p>The actual website grabs more information the my test website does.</p>
  
  <p>Here is the code the I've used on my test website.</p>
  
  <p>image.php</p>
  
  <pre><code>$query = mysql_query("SELECT * FROM images LIMIT 1");
  while($row = mysql_fetch_assoc($query)){
  
      $image_id = $row['id'];
      echo "&lt;img src=showimage.php?id=".$image_id."&gt;";
  }
  </code></pre>
  
  <p>Here is how I'm grabbing the image from the database and displaying it.</p>
  
  <p>showimage.php</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>Using that code on the test website works fine, there's no problem there.</p>
  
  <p>Here is my code for the actual website.</p>
  
  <p>sites.php</p>
  
  <pre><code>$select = mysql_query("SELECT * FROM sites");
              while($row = mysql_fetch_assoc($select)){
  
                  $image_id = $row['id'];
  
                  echo '
                      &lt;tr class="bottom"&gt;&lt;td&gt;'.$row['host'].'&lt;/td&gt;
                      &lt;td&gt;'.$row['currency'].''.$row['price'].' every '.$row['payment'].'&lt;/td&gt;
                      &lt;td&gt;'.$row['domain'].'&lt;/td&gt;
                      &lt;td&gt;'.$row['paid_currency'].''.$row['paid_domain'].'&lt;/td&gt;
                      &lt;td&gt;'.$row['features'].'&lt;/td&gt;
                      &lt;td&gt;
                          &lt;span title="Edit '.$row['id'].'"&gt;&lt;a href="edit.php?id='.$row['id'].'"&gt;&lt;img src="images/edit.png" alt="Edit"&gt;&lt;/a&gt;&lt;/span&gt;
                          &lt;span title="Delete '.$row['id'].'"&gt;&lt;a href="inc/delete.php?id='.$row['id'].'"&gt;&lt;img src="images/delete.png" alt="Delete"&gt;&lt;/a&gt;&lt;/span&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;img src=showimage.php?id='.$image_id.'&gt;&lt;/td&gt;&lt;/tr&gt;
                      ';
              }
  </code></pre>
  
  <p>That using the showimage.php file to grab the image from the database, but isn't working at all.</p>