title: export mysql table data to csv file through php..html also get dumped
body: <p>So I was trying to export mysql table to csv file via php. This is the code<br></p>
  
  <pre><code>&lt;?php if (isset($_POST['exp'])) {
  
      header('Content-Type: text/csv; charset=utf-8');
      header('Content-Disposition: attachment; filename=data.csv');
  
      $output = fopen('php://output', 'w');
  
      fputcsv($output, array('User ID', 'User Name', 'Password'));
      $con = mysqli_connect('localhost', 'root', 'pass', 'xyz');
      $rows = mysqli_query($con, 'SELECT * FROM users');
  
      while ($row = mysqli_fetch_assoc($rows)) {
        fputcsv($output, $row);
      }
      fclose($output);
      mysqli_close($con);
    }
  ?&gt;
  
  &lt;div&gt;
    &lt;form action="#" method="post"&gt;
      &lt;input type="submit" value="Export" name="exp" /&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Every thing is fine but the html part also gets dumped in the csv file. here is screen shot of the csv
  <img src="https://i.stack.imgur.com/7fERK.jpg" alt="csv output"></p>
  
  <p>Why is that happening? Am I doing anything wrong?</p>