title: (PHP) The Image cannot be displayed because it contains errors
body: <p>I've read almost all topics related to this. i dont know whats causing it.</p>
  
  <p>This is code for showing images</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;?php 
  
                      mysql_connect('localhost','root','') or die("Unable to Connect: ".mysql_error());
                      mysql_select_db("punjabi") or die("Unable to Select Database: ".mysql_error());
  
                      $sql = "SELECT imagename, mimetype, imagedata
                              FROM images WHERE ID = 1";
  
                      $result = @mysql_query($sql);
                      if(!$result)
                      {
                          die(mysql_error());
                      }
  
                      $file = mysql_fetch_array($result);
  
                      $imagename = $file['imagename'];
                      $mimetype = $file['mimetype'];
                      $imagedata = $file['imagedata'];
  
                      header("content-type: $mimetype");
  
                      echo($imagedata);
  
  ?&gt;
  </code></pre>
  
  <p>This is the code for inserting images</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Add Post&lt;/title&gt;
  &lt;style type="text/css"&gt;
      *
      {
          margin:0px;
          padding:0px;
      }
  &lt;/style&gt;
  
  &lt;/head&gt;
  
  &lt;body bgcolor="#333333"&gt;
  
  &lt;?php if(isset($_POST['submit'])):
          {
  
  
              if (!is_uploaded_file($_FILES['uploadfile']['tmp_name']))
              {
                  die("$uploadfile is not an uploaded file!");
              }
  
              $uploadfile = $_FILES['uploadfile']['tmp_name'];
              $uploadname = $_FILES['uploadfile']['name'];
              $uploadtype = $_FILES['uploadfile']['type'];
              $uploaddesc = $_POST['desc'];
  
  
              $tempfile = fopen($uploadfile,'rb');
              $filedata = fread($tempfile,filesize($uploadfile));
              $filedata = addslashes($filedata);
              $sql = "INSERT INTO images SET
              imagename = '$uploadname',
              mimetype = '$uploadtype',
              description = '$uploaddesc',
              imagedata = '$filedata'";
              $ok = @mysql_query($sql);
              if (!$ok) die("Database error storing file: " .mysql_error());
  
              $sql = "Select id from images where imagename = '$uploadname'";
              $result = @mysql_query($sql);
              if(!$result) die(mysql_error());
              if(mysql_num_rows($result)!=1) die(mysql_error());
  
              $row = mysql_fetch_array($result);
              $imageid = $row['id'];
  
              $title = $_POST['title'];
              $content = $_POST['content'];
  
              $sql = "INSERT into posts SET
                      title = '$title',
                      content = '$content',
                      imageid = '$imageid'";
              if(!@mysql_query($sql))
              {
                  die(mysql_error());
              }
  
  
              header("Location:http://localhost/punjabi/adminhome.php");  
  
          }
  
  
  ?&gt;
  
  &lt;?php else: ?&gt;
  
      &lt;div id="post"&gt;
          &lt;form action="&lt;?php echo($_SERVER['PHP_SELF']) ?&gt;" method="post" enctype="multipart/form-data" &gt;
              Title: &lt;input type="text" name="title" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
              Content:&lt;br /&gt; &lt;textarea cols=100 rows="40" wrap="hard" name="content" /&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;
              Image: &lt;input type="file" name="uploadfile" /&gt;&lt;br /&gt;&lt;br /&gt;
              Image Desc: &lt;input type="text" name="desc" /&gt;&lt;br /&gt;&lt;br /&gt;
              &lt;input type="submit" value="Submit" name="submit" /&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  
  &lt;?php endif; ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And This is the Table Structure:</p>
  
  <pre><code>CREATE TABLE filestore (
  -&gt; ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  -&gt; FileName VARCHAR(255) NOT NULL,
  -&gt; MimeType VARCHAR(50) NOT NULL,
  -&gt; Description VARCHAR(255) NOT NULL,
  -&gt; FileData MEDIUMBLOB
  -&gt;);
  </code></pre>
  
  <p>And Help would be appreciated!</p>