title: PHP: Exporting HTML table to Excel includes entire form?
body: <p>I have a php file which shows an html form, and on submit, creates an html table from mysql data, and exports it to excel. </p>
  
  <p>My issue is that the entire html form is outputted to the excel file along with the table data.</p>
  
  <p>My code is:</p>
  
  <pre><code>&lt;html form..&gt;
  
  &lt;?php
  if(isset($_POST['submit'])){
  //get sql data and create html table in variable (ie $data="&lt;table&gt;..")
  
  header("Content-type: application/vnd.ms-excel");
  header("Content-Disposition: attachment; filename=$file");
  echo "$data";}
  ?&gt;
  </code></pre>
  
  <p>i want only "$data" to show in my .xls, but instead the whole <code>&lt;form&gt;</code> is displaying, submit buttons and all.</p>
  
  <p>thank you.</p>