JaguarPC Community - Web Hosting, VPS Hosting, cPanel VPS Hosting, Hybrid Servers, Dedicated Servers, Virutal Private Servers, Managed Servers
» Hosting Community Support
» Design and Development
:
Warning: Cannot modify header information - headers already sent by (output started a
| Design and Development Get help setting up forums, databases, or discuss any form of scripting. Have a question or comment about a website? Or just show off your own site! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
JPC Member
Join Date: Oct 2006
Posts: 19
|
Warning: Cannot modify header information - headers already sent by (output started a
hi
iam new php, now i want write a html form datas to Excel file, for that i wrote following code, but it displaying errors like "Warning: Cannot modify header information - headers already sent by (output started at c:\program files\apache group\Apache\htdocs\sample\excel.php:9) in c:\program files\apache group\Apache\htdocs\sample\excel.php on line 56". Code : <?php $db=mysql_connect('localhost', 'root', 'success'); if(!$db) { echo "error in connecting............."; } mysql_select_db('byt'); $result = mysql_query('select * from users'); $count = mysql_num_fields($result); for ($i = 0; $i < $count; $i++){ $header .= mysql_field_name($result, $i)."\t"; } while($row = mysql_fetch_row($result)){ $line = ''; foreach($row as $value){ if(!isset($value) || $value == ""){ $value = "\t"; }else{ $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r", "", $data); if ($data == "") { $data = "\nno matching records found\n"; } header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename=excelfile.xls'); header('Pragma: no-cache'); header("Expires: 0"); echo $header."\n".$data; ?> whats the wrong with code..... pls help me its urgent task for me Regards Chinna |
|
|
|
|
|
#2 |
|
Community Liason
|
the only thing I see right off is
Code:
if(!$db)
{
echo "error in connecting.............";'
}
Change it to Code:
if(!$db)
{
echo "error in connecting.............";'
die();
}
Code:
if(!$db)
{
echo "error in connecting.............";'
}else{
__________________
------------------------- the_ancient Cyclone Software Solutions Web Design - Graphic Design & Printing - Virtual PBX Systems |
|
|
|
|
|
#3 |
|
Jag Veteran
Join Date: Sep 2001
Location: Wichita, KS
Posts: 1,641
|
also, it will break if you have any space before your <?
__________________
I do not work for Jaguar PC. My responses are not official policy for JPC. I simply moderate the forums. |
|
|
|
|
|
#4 |
|
Yeah, I know a LOT!
Join Date: Mar 2003
Location: Arizona Uplands Intelligence Quotient: 138+
Posts: 10,384
|
Pretty self-explanatory! You're calling the header twice and that's a no-no...
![]() Comment out one of those lines, and it should take care of itself.
__________________
DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient. |
|
|
|
|
|
#5 |
|
Now with 46.3% more slack
|
Use the php tags around php code in the forum please...
PHP Code:
What is happening is that the error or warning itself is sending output and headers. You can shut off warnings and error output, but you'll have to fix the errors anyway. Try adding the lines as I suggest in your code above. Good luck. Last edited by Ron; 10-19-2006 at 10:27 PM. Reason: typo |
|
|
|
|
|
#6 |
|
Community Liason
|
__________________
------------------------- the_ancient Cyclone Software Solutions Web Design - Graphic Design & Printing - Virtual PBX Systems |
|
|
|
|
|
#7 |
|
Now with 46.3% more slack
|
[code] Tags are ok, too...
|
|
|
|
|
|
#8 |
|
JPC Member
Join Date: Oct 2006
Posts: 19
|
thanks for replyed, i tryed the above suggestions but still iam getting same errors...
Regards Chinna |
|
|
|
|
|
#9 |
|
Now with 46.3% more slack
|
No way, unless this code is being called from another program. The line number in the error would change at a minimum.
|
|
|
|
|
|
#10 | |
|
JPC Member
Join Date: Oct 2006
Posts: 19
|
the following code also displaying Warning: Cannot modify header information - headers already sent by
Quote:
is there any specific configuration in php.ini to use "header"?.. Regards Chinna Last edited by chinna; 10-19-2006 at 10:55 PM. |
|
|
|
|
|
|
#11 | |
|
Yeah, I know a LOT!
Join Date: Mar 2003
Location: Arizona Uplands Intelligence Quotient: 138+
Posts: 10,384
|
Quote:
That's a thought! You might try adding or changing the state of: Code:
output_buffering=on;
__________________
DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient. |
|
|
|
|
|
|
#12 | |
|
Community Liason
|
Quote:
you can not send ANYTHING at all before you send header, no html, no text, NOTHING. Make sure your not
__________________
------------------------- the_ancient Cyclone Software Solutions Web Design - Graphic Design & Printing - Virtual PBX Systems |
|
|
|
|
|
|
#13 |
|
Now with 46.3% more slack
|
hmmmmmm
I don't think a space before <? will cause this problem inside a .php file; perhaps in a .html file.... OR if he's got a handler set to handle .php as parsed .html? How is this code being called? Straight from a URL or from another script? |
|
|
|
|
|
#14 |
|
JPC Member
Join Date: Oct 2006
Posts: 19
|
thanks thanks a lot i found a error... its the space before <?php ..now working properly....thanks ron .. i will meet with next problem..
best reagrds Chinna |
|
|
|
|
|
#15 | |
|
Community Liason
|
Quote:
Test it...
__________________
------------------------- the_ancient Cyclone Software Solutions Web Design - Graphic Design & Printing - Virtual PBX Systems |
|
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
















Linear Mode
