title: PHP code to export to excel specific filtered date
body: <p>I am trying to write a simple PHP code to export to excel the data selected between two dates. On clicking the 'Export to Excel' button in the HTML page which will redirect to php file with the below code, my excel is not getting downloaded. Can someone tell me where the error is and what modification needs to be made. Tell me in the simplest way possible.</p>
  
  <pre><code>&lt;?php
  include ("conn.php");
       if(isset($_POST["export"]))
   {
      $connect = mysqli_connect("localhost", "root", "", "cruddatabase");  
      header('Content-Type: text/csv; charset=utf-8');  
      header('Content-Disposition: attachment; filename=data.csv');  
      $output = fopen("php://output", "w");  
      fputcsv($output, array('ID Company Name','Company Type','Name','Email','Contact Number','Anniversary Date','Organisation Name','Meeting','Timeline For Conversation','Currency','Card','Locations'));  
      $query = "SELECT * FROM crudtable WHERE adate &gt;= '$fdate' AND adate &lt;= '$tdate' ORDER BY adate DESC";  
      $result = mysqli_query($con, $query);  
      while($row = mysqli_fetch_assoc($result))  
      {  
           fputcsv($output, $row);  
      }  
      fclose($output);  
  }  
   ?&gt;
  </code></pre>