PHP headers already sent Error

I have this error and it is driving me crazt. I don't know why it is happening:

"Warning: Cannot modify header information - headers already sent by (output started at /admin/db_connect.php"

I have checked for spaces before the php tags in the file and the db_connect file.

My includes look like this:

<?php
include("../pChart2.1.1/class/pData.class.php");
include("../pChart2.1.1/class/pDraw.class.php");
include("../pChart2.1.1/class/pImage.class.php");
include("../admin/db_connect.php");

$GrabIt = $_GET["test"];  

And then some DB query.

What am I doing wrongly?

Thanks.
SolutionabcAsked:
Who is Participating?
 
Lukasz ChmielewskiConnect With a Mentor Commented:
You need to show us the db_connect.php and also the rest of the script. If it says it has already outputted the header then it did. Some of the connection command may do that.
0
 
greenbug2002Connect With a Mentor Commented:
somthing in one of those files must be returning data to the webbrowser for the headers alredy sent warning to be triggered try comenting out each include to narrow it down
0
 
AriMcConnect With a Mentor Commented:
Also check all of your PHP-files for empty lines before and after the starting and ending tags

<?php
?>

0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
Beverley PortlockConnect With a Mentor Commented:
The clue to the error is given by this partially complete error line

output started at /admin/db_connect.php

This error normally has some additional text that should look like this

output started at /admin/db_connect.php at line 1234

and that indicates the line of the script that commenced the output. The output could be as simple as a blank line before a <?php tag or after a ?> tag or an echo or some HTML. You have two choices at this point

1. Stop the line in question from outputting text.

2. At the top of the very first script add this line as early as possible

ob_start();

Like so

<?php
   ob_start();
   ... etc....

http://www.php.net/ob_start
0
 
Ray PaseurConnect With a Mentor Commented:
ob_start() may do the trick for you, but here is what I would do.

Run the code snippet - and that is all - and look at the browser output with "view source."  You may find the output in there!  And if it is useless, eliminate it.
<?php
include("../pChart2.1.1/class/pData.class.php");
include("../pChart2.1.1/class/pDraw.class.php");
include("../pChart2.1.1/class/pImage.class.php");
include("../admin/db_connect.php");
die();

Open in new window

0
 
SolutionabcAuthor Commented:
I tried bportlock suggestions and got a message that says:
"The image "http://www...etc/index.php/get=test" cannot be displayed because it contains errors.

I tried Rays and nothing appeared in the source.

It looks like the script that is dependent on the include class files does not like any output before it is run.
that script draws a graph and outputs it as an image.

I have some db queries that output some information before the image should display. If I put the image script before the output text the image will work but the output text does not show.

any suggestions?
thanks!
0
 
Ray PaseurCommented:
any suggestions?

Yes, here is a suggestion.  Please do not waste your time and ours with things like "http://www...etc/index.php/get=test".  Instead tell us the complete information -- the actual URLs, the full error messages.  There is little point in making us guess blindly, when if you give us the information we can look and see, and maybe help find a solution.
0
 
SolutionabcAuthor Commented:
I blanked out the url. How is listing the full URL going to help you help me?

The parameter being passed to it would be the only useful thing if even that.... and it was included above.

0
 
SolutionabcAuthor Commented:
anyways, I got it.. ended up putting EVERYTHING into an include file and called it in with an img tag.

thx.
0
 
Ray PaseurCommented:
Yes, I know you blanked out the URL.  How will anyone here at EE be able to see the web page and the generated HTML?  
0
 
SolutionabcAuthor Commented:
If seeing the generated html was important to you then I would rather copy and paste it into here.

thx.
0
 
Ray PaseurCommented:
@Solutionabc: The point is rather simple.  The more you hide from us, the less likely we are to be able to help you.  The more you show us, the more likely we are to be able to help you.  We are only experts, not clairvoyant, and we cannot guess about what might or might not be happening in a script when we cannot see the script and we cannot see the output.  

Imagine a chef who said, "My diners say the meatloaf tastes rancid.  What is wrong?"  When we get partial error messages and no visibility of the cause, we have no more information than we would for the chef.  So please give us all the details.   If you have data that you want to protect, copy it, obscure it, and make a test case that demonstrates the problem.  Often you will find (at least I do) that preparing an isolated test case is all you need to do to solve the problem!

Best of luck with it, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.