mysql - My PHP generated CSV file is saving as a PHP file -


i've learned how create csv files mysql data stackoverflow question. problem is, reason when call code, tries save file called index.php (which current page). inside index.php file data table there, separated commas. i'm guessing have small typo somewhere, after playing code cannot find it. can help.

$result=mysql_query("select * tbl_email"); if(mysql_num_rows($result)) {   header ("content-type: application/csv content-disposition:\"inline; filename=messages.csv\"");   echo "ref #,company,name,email,message,date\n";   while($row = mysql_fetch_row($result)) {     $companyname = mysql_query("select company tbl_users user_id ='$row[1]'");     $datname = mysql_fetch_array($companyname);     echo"$row[7],$datname[company],$row[2],$row[4],$row[5],$row[6]\n";   }   die(); } 

you need multiple header() calls rather 1 call supplies multiple headers on single line, , believe appropriate mime type csv text/csv.

header("content-type: text/csv"); header("content-disposition: inline; filename=messages.csv"); 

and more commonly, use content-disposition: attachment force download.

header("content-type: text/csv"); header("content-disposition: attachment; filename=messages.csv"); 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -