Cannot Modify Header Information

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Cannot Modify Header Information

Postby libertyct » 20. January 2007 21:16

just a quick question, i was trying this code, creating an excel file
but i get a "Cannot Modify Header Information" error, what am i doing wrong?

$query = "SELECT fname, lname FROM students";
$result = mysql_query($query) or die('Error, query failed');

$tsv = array();
$html = array();
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
$tsv[] = implode("\t", $row);
$html[] = "<tr><td>" .implode("</td><td>", $row) . "</td></tr>";
}

$tsv = implode("\r\n", $tsv);
$html = "<table>" . implode("\r\n", $html) . "</table>";

$fileName = 'mysql-to-excel.xls';
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$fileName");

echo $tsv;
//echo $html;
libertyct
 
Posts: 4
Joined: 11. January 2007 13:48

Postby Wiedmann » 20. January 2007 22:49

but i get a "Cannot Modify Header Information" error, what am i doing wrong?

There is an output before the header() function.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby xnemesis » 21. January 2007 04:57

Check where it is in your HTML code. The placement of certain functions is VERY important. Especially when using header() check out php.net for more information
xnemesis
 
Posts: 20
Joined: 13. November 2006 02:52


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 134 guests