title: Accessing image from database using PHP
body: <p>I am having problem in accessing image that I have saved as Long BLOB type in my sql table add_deal, the problem that I am facing is that I am unable to access image and display it on my browser. When I run the programme I see a broken page. I have tried placing "header('Content-type: image/jpeg');" above echo which in turn gives an error stating "image cannot be displayed because it contains errors" I have saved my image as:</p>
  
  <pre><code>$image = addslashes($_FILES['image']['tmp_name']);
          $name=addslashes($_FILES['image']['name']);
          $image_size=getimagesize($_FILES['image']['tmp_name']);
          $deal_type = $_POST['dealtype'];
          $description = $_POST['description'];
          $quantity = $_POST['quantity'];
          $validity = $_POST['validity'];
          $price=$_POST['cost'];
  
      $qry="INSERT INTO `add_deal`(`dealtype`, `description`, `quantity`, `validity`, `price`, `image`, `name`) VALUES ('$deal_type','$description','$quantity','$validity','$price','$image','$name')";
      $result=mysqli_query($db,$qry);
      if(! $result ) {
            die("Query FAILED. " . mysqli_error($db));
          }
      else
      {
          echo "Your Deal has been placed in your Gallery";
          echo "&lt;br/&gt;Go to &lt;a href='dealhome.php'&gt;home&lt;/a&gt; page to see whats in your gallery&lt;/b&gt;";
      }
  </code></pre>
  
  <p>and accessing it as:</p>
  
  <pre><code>    if(! $result ) {
            die("Query FAILED. " . mysqli_error($db));
          }
              else
      {
  
      if ($result-&gt;num_rows &gt; 0) {
          // output data of each row
          //echo "&lt;table&gt;";
      while($row = mysqli_fetch_row($result)) {
      header('Content-type: image/jpeg');
      echo $row['image'];
  
      }
      }
      //echo "&lt;/table&gt;";
      }
  </code></pre>