title: Download File from Database
body: <p>With the database connected properly, when I try to download the files, the contents I get is a php page of this file which I am working on. Instead of the file which was uploaded to the database. Why is this happening?</p>
  
  <pre><code>$query = "SELECT id, name FROM docu";
  $result = mysqli_query($con,$query) or die('Error, query failed');
  
  if(mysqli_num_rows($result)==0){
      echo "Database is empty &lt;br&gt;";
  }
  else{
      while(list($id, $name) = mysqli_fetch_array($result)){
          echo "&lt;a href='download.php?id='$id&gt;$name&lt;/a&gt;&lt;br&gt;";
      }
  }
  
  if(isset($_GET['id'])){
      $id    = $_GET['id'];   
      $query = "SELECT id, name, type, size, content FROM docu WHERE id = '$id'";       
      $result = mysqli_query($con,$query) or die('Error, query failed');
      list($id, $name, $type, $size, $content) =  mysqli_fetch_row($result);
      header("Content-Disposition: attachment; filename='$name'");
      header("Content-type: $type");
      header("Content-length: $size");
      echo $content;
      exit;
  }
  </code></pre>