title: Exporting html (mysql populated) table to excel file
body: <p>I am trying to query a mysql database and display data in a table.  That part is working.  At the moment, it is set up for displaying the
   results within the certain date range.  </p>
  
  <p>I now want to take the table and make a button that allows you to export it to an Excel file.  Before I added the option of choosing a date range, you were able to export to Excel, but now it seems that the second file does not know what table I am talking about.  I tried using POST to send the values of the data and re-query on the other page.  </p>
  
  <p>When I click the button to export, the excel document that is downloaded is empty, (though it has a size). Any help please?</p>
  
  <p>-----Query mysql---------  </p>
  
  <pre><code> &lt;html&gt;&lt;head&gt;&lt;title&gt;New Production Rejections&lt;/title&gt;&lt;/head&gt;&lt;/html&gt;
      &lt;?php 
  
      include("config.php");
      //get serial from submitted data
          //$serial = $_POST['sNumber'];
          //if the submitted data is empty
          $serial = $_POST['entryDate'];
      $dateEnd = $_POST['entryDate2'];
          //parse the serial from the link in tracker
      ?&gt;
          &lt;form method="post" action="&lt;?php echo "queryNewProdRejections.php?"?&gt;"&gt;
          Search between dates: (Format: YYYY-MM-DD)&lt;input type='text' size='20' maxlength='20' name='entryDate'&gt; - &lt;input type='text' size='20' maxlength='20' name='entryDate2'&gt;
          &lt;input type="submit" value="Search Date Range"&gt;&lt;br/&gt;&lt;/form&gt;
  
      &lt;?php
  
  
      //query based on approved date that is nothing, repaired date that is nothing, 
      //tech is a real tech, location that is not Revite (RVP), action was to replace, 
      //and the status is not (declined or skipped).
  
      $query = "SELECT *
      FROM `rma`
      WHERE `origin` NOT LIKE 'Field_failure'
      AND `origin` NOT LIKE 'DOA_at_Customer'
      AND `origin` NOT LIKE 'Sweden_Fail_VI'
      AND `entry` &gt; '$serial' AND `entry` &lt; '$dateEnd'";
      $data = mysql_query($query) or die(mysql_error());
  
      //Create a table with the array of data from repairs, based on the previous query
  
      echo "&lt;table border='1'&gt;&lt;tr&gt;&lt;th&gt;RMA&lt;/th&gt;&lt;th&gt;Product&lt;/th&gt;&lt;th&gt;Serial&lt;/th&gt;&lt;th&gt;Origin&lt;/th&gt;&lt;th&gt;Return To&lt;/th&gt;&lt;th&gt;Credit Num&lt;/th&gt;&lt;th&gt;Order&lt;/th&gt;&lt;th&gt;Entry Date&lt;/th&gt;&lt;th&gt;Tech&lt;/th&gt;&lt;th&gt;Traking Num&lt;/th&gt;&lt;/tr&gt;";
  
      while($row = mysql_fetch_array($data)){ 
          print "&lt;tr&gt;&lt;td&gt;".$row['intrma']."&lt;/td&gt;&lt;td&gt;".$row['product']."&lt;/td&gt;&lt;td&gt;".$row['serial']."&lt;/td&gt;&lt;td&gt;".$row['origin']."&lt;/td&gt;&lt;td&gt;".$row['retto']."&lt;/td&gt;&lt;td&gt;".$row['creditnum']."&lt;/td&gt;&lt;td&gt;".$row['ordernum']."&lt;/td&gt;&lt;td&gt;".$row['entry']."&lt;/td&gt;&lt;td&gt;".$row['tech']."&lt;/td&gt;&lt;td&gt;".$row['tracknum']."&lt;/td&gt;&lt;/tr&gt;";
      }
      print "&lt;/table&gt;";
  
      ?&gt;
      &lt;html&gt;
      &lt;form method="post" action="saveQueryToExcel.php"&gt;
      &lt;input type='hidden' name='ent_1' value="&lt;?php echo $_POST['entryDate']; ?&gt;"&gt;
      &lt;input type='hidden' name='ent_2' value="&lt;?php echo $_POST['entryDate2']; ?&gt;"&gt;
        &lt;input type="submit" value="Save to Excel"&gt;
      &lt;/form&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>---------------Print to Excel File -- (saveQueryToExcel.php)</p>
  
  <pre><code>&lt;html&gt;&lt;head&gt;&lt;title&gt;New Production Rejections&lt;/title&gt;&lt;/head&gt;&lt;/html&gt;
  
  &lt;?php
  error_reporting(0);
  
  $dateBeg=$_POST['ent_1'];
  $dateEnd=$_POST['ent_2'];
  
  //Connect to the database, repairs in maprdweb
  include("config.php");
  
  //query based on approved date that is nothing, repaired date that is nothing, 
  //tech is a real tech, location that is not Revite (RVP), action was to replace, 
  //and the status is not (declined or skipped).
  
  $query = "SELECT *
  FROM `rma`
  WHERE `origin` NOT LIKE 'Field_failure'
  AND `origin` NOT LIKE 'DOA_at_Customer'
  AND `origin` NOT LIKE 'Sweden_Fail_VI'
  AND `entry` &gt; '$dateBeg' AND `entry` &lt; '$dateEnd'";
  $data = mysql_query($query) or die(mysql_error());
  
  //Create a table with the array of data from repairs, based on the previous query
  header('Content-type: application/vnd.ms-excel');
  
  echo "&lt;table border='1'&gt;&lt;tr&gt;&lt;th&gt;RMA&lt;/th&gt;&lt;th&gt;Product&lt;/th&gt;&lt;th&gt;Serial&lt;/th&gt;&lt;th&gt;Origin&lt;/th&gt;&lt;th&gt;Return To&lt;/th&gt;&lt;th&gt;Credit Num&lt;/th&gt;&lt;th&gt;Order&lt;/th&gt;&lt;th&gt;Entry Date&lt;/th&gt;&lt;th&gt;Tech&lt;/th&gt;&lt;th&gt;Traking Num&lt;/th&gt;&lt;/tr&gt;";
  
  while($row = mysql_fetch_array($data)){ 
      print "&lt;tr&gt;&lt;td&gt;".$row['intrma']."&lt;/td&gt;&lt;td&gt;".$row['product']."&lt;/td&gt;&lt;td&gt;".$row['serial']."&lt;/td&gt;&lt;td&gt;".$row['origin']."&lt;/td&gt;&lt;td&gt;".$row['retto']."&lt;/td&gt;&lt;td&gt;".$row['creditnum']."&lt;/td&gt;&lt;td&gt;".$row['ordernum']."&lt;/td&gt;&lt;td&gt;".$row['entry']."&lt;/td&gt;&lt;td&gt;".$row['tech']."&lt;/td&gt;&lt;td&gt;".$row['tracknum']."&lt;/td&gt;&lt;/tr&gt;";
  }
  print "&lt;/table&gt;";
  ?&gt;
  </code></pre>