-2

i have this code to export from mysql to excell in wordpress i am calling this file with link

    <?php include("header.php"); 

    $table = 'driver_detail';
    $file = 'export';

    $result = mysql_query("SHOW COLUMNS FROM ".$table."");
    $i = 0;
    if (mysql_num_rows($result) > 0) {
    while ($row = mysql_fetch_assoc($result)) {
    $csv_output .= $row['Field']."; ";
    $i++;
    }
    }
    $csv_output .= "\n";
    $values = mysql_query("SELECT * FROM ".$table."");
    while ($rowr = mysql_fetch_row($values)) {
    for ($j=0;$j<$i;$j++) {
    $csv_output .= $rowr[$j]."; ";
    }
    $csv_output .= "\n";
    }

    $filename = $file."_".date("Y-m-d_H-i",time());
    header("Content-type: application/vnd.ms-excel");
    header("Content-disposition: csv" . date("Y-m-d") . ".csv");
    header( "Content-disposition: filename=".$filename.".csv");
    print $csv_output;
    exit;
    ?>

but i am having this error .. how to fix this

 Warning: Cannot modify header information - headers already sent by (output started at /home5/revoluv0/public_html/proj/autobodyparts/get-details/header.php:3) in /home5/revoluv0/public_html/proj/autobodyparts/get-details/export-driver.php on line 24
Gordon
  • 312,688
  • 75
  • 539
  • 559
Atif Azad
  • 75
  • 1
  • 10
  • Please check [this question](http://stackoverflow.com/q/8028957/1105514). But as a quick solution, please move all of your `header()` calls to the top of your file, right before the inclusion, because the error says that the output started in `header.php`. – Adi Mar 16 '13 at 09:48
  • what is in header.php? May be some content has been sent from that file. ( Blank spaces ) – Kumar Pratik Mar 16 '13 at 09:51
  • in header i have wp-load.php and other external js and css i am accessing these file from the root folder – Atif Azad Mar 16 '13 at 09:53

1 Answers1

0

Something has been print before the header even a single space lead to this problem.

Thirumalai murugan
  • 5,698
  • 8
  • 32
  • 54