Cannot modify header information : Export CVS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Cannot modify header information : Export CVS

Post 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";

}
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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;
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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:
User avatar
phpdevuk
Forum Contributor
Posts: 220
Joined: Mon Jul 04, 2005 5:31 am
Location: UK
Contact:

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

phpdevuk wrote: n00b is right echoing $header wouldn't do much.
he means scrotaye ;d

(sorry n00b) =)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post 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.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

lest we all forget viewtopic.php?t=1157

#36
Post Reply