导出.CSV文件,如果我用列名称导出它,它告诉我它是一个SYLK格式[重复]

This question already has an answer here:

Exporting contents from an SQL Database table to a .csv file. If I add in the column names it gives me these errors when trying to open the downloaded .csv file:

Error #1

Error #2

However, if I export it without the columns it will open up just fine without errors. I've tried changing the Content-Type: from text/csv to application/csv, didn't change anything. I'm out of ideas.

<?php
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=applications.csv");
header("Pragma: no-cache");
header("Expires: 0");

ini_set('display_errors',1);
$private=1;
error_reporting(E_ALL ^ E_NOTICE);

mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("cif") or die(mysql_error());

$query = "SELECT * FROM applications";
$select_c = mysql_query($query) or die(mysql_error());

/* The line below is what I comment out to remove the column names */
$result.="ID,LAST_NAME,FIRST_NAME,ORGANIZATION,TITLE
"; 
/* The line above is what I comment out to remove the column names */

while ($row = mysql_fetch_array($select_c, MYSQL_ASSOC))
{
    $result.="{$row['ID']},";
    $result.="{$row['LAST_NAME']},";
    $result.="{$row['FIRST_NAME']},";
    $result.="{$row['ORGANIZATION']},";
    $result.="{$row['TITLE']},";
    $result.="
";

}
    echo $result; 
?>
</div>

Looks like you have a number of columns mismatch.

The header row has 5 entries, but each subsequent row has 6 (because of the trailing comma).

You can either add a comma to the end of your header row or remove the trailing comma from the data rows.


EDIT: SYLK files start with "ID". http://support.microsoft.com/kb/323626

Make your first column name not start with "ID" and you'll be good to go.