Page 1 of 1

Cannot modify header information : Export CVS

Posted: Wed Sep 21, 2005 2:36 am
by facets
Can any folk see why the following might not work?
It's spitting :

Warning: Cannot modify header information - headers already sent by (output started at \www\collotype\materialsregister\template.inc:622) in \www\collotype\includes\functions.inc.php on line 140 (Which is the first Header Line).

TIA, Will

Code: Select all

function exportSAData () {
	
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=SMSRealty-Sales-Leads-".date("Y-m-d").".csv");
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");

// You do not need to change the function

$query = mysql_query("SELECT ausapapersummary.summaryId, aupapercategory.paperCategory, ausapapersummary.colloPaperName, ausapapersummary.manufacturerName, ausapapersummary.cpl, austock.stockDescription, auadhesive.adhesiveDescription, auliner.linerDescription, ausupplier.supplier FROM ausapapersummary	LEFT JOIN aupapercategory ON ausapapersummary.paperCategoryId = aupapercategory.papercategoryId LEFT JOIN austock ON ausapapersummary.stockId = austock.StockId	LEFT JOIN auadhesive ON ausapapersummary.adhesiveId = auadhesive.adhesiveId	LEFT JOIN auliner ON ausapapersummary.linerId = auliner.linerId	LEFT JOIN ausupplier ON ausapapersummary.supplierId = ausupplier.supplierId WHERE 1=1");
$row = mysql_fetch_array($query);

print "$header\n$row";

}

Posted: Wed Sep 21, 2005 2:41 am
by s.dot
my guess is that this is already coming after something has been printed to the browser. also print $header will not work because $header is not a variable. You're setting the header for the php page to send to the browser, not making it a variable :P

if you wanted to see what the header would be you could do

Code: Select all

$header = "header(property: value)";
$header .= "header(property: value)";
$header .= "header(proptery: value)";

echo $header;

Posted: Wed Sep 21, 2005 2:53 am
by n00b Saibot
output started at \www\collotype\materialsregister\template.inc:622
Error very much says all and also points out the location of the output. Remove any blankspace 'cause they also start the output. :wink:

Posted: Wed Sep 21, 2005 3:01 am
by phpdevuk
check the page that calls the function and look for any output before the call, even white space can cause problems sometimes. The headers should be the first output on the page, so before this function is called no output but you can have php code. n00b is right echoing $header wouldn't do much.

Posted: Wed Sep 21, 2005 3:10 am
by s.dot
phpdevuk wrote: n00b is right echoing $header wouldn't do much.
he means scrotaye ;d

(sorry n00b) =)

Posted: Wed Sep 21, 2005 3:10 am
by facets
I should find a better example of how to do this I think.
All I want to do is output my select statement to a file.

Posted: Wed Sep 21, 2005 3:26 am
by n00b Saibot
scrotaye wrote:
phpdevuk wrote: n00b is right echoing $header wouldn't do much.
he means scrotaye ;d

(sorry n00b) =)
really :!: :twisted: he means ME 8)

Posted: Wed Sep 21, 2005 7:03 am
by feyd
lest we all forget viewtopic.php?t=1157

#36