0

trying to export my table to CSV file but I seem to be lost on what am doing wrong, I have my loaddata.php that has table that shows fields I have my Connection.php that will have database connection but when I run result what am getting is it exporting CSV with columns, but data is is bring back loaddata.php page with HTML formatting and every result

I have tried moving the included "loaddata.php" than I get brought back blank excel page with columns

<?php include('connection.php');


 if(isset($_POST["export"])){

  header('Content-Type: text/csv; charset=utf-8');

 header('Content-Disposition: attachment; filename=loaddata.csv'); 

 $output = fopen("php://output", "w");

  fputcsv($output, array(
       'row number',
       'Position ID', 
       'Description', 
       'firstname', 
       'lastname', 
        'country ',
        'PhoneNumber'));


      include ("loaddata.php") 
      $sqlcsv = "SELECT * FROM employeeTable";

      $resultcsv = mysqli_query($conn,$sqlcsv)  
     or die('Invalid query sqlcsv: ' . mysqli_error());


         while ($row = mysqli_fetch_assoc($resultcsv))
         {
          fputcsv($output, $row);
         }
          fclose($output);
         }
        ?>
  • 1
    Please [edit] your question and include the contents of `loaddata.php`. – Dave Oct 31 '19 at 23:05
  • What happens if you comment out `include ("loaddata.php")`? It looks like you are getting all of the data in what you posted without needing that include. – Dave Oct 31 '19 at 23:07
  • why the include ("loaddata.php") line? Also I believe the array you are going to get will be fieldname:data for each value. You need to parse it more, no? You may also want to write a byte-order-marker for the unicode encoding...https://stackoverflow.com/questions/25686191/adding-bom-to-csv-file-using-fputcsv – pcalkins Oct 31 '19 at 23:10

0 Answers0