The error you are seeing is a result of sending HTTP headers after content has already been sent. As you output content in a PHP script, the server immediately sends that output to the browser. So, you can't send HTTP headers where the response body is to appear.
In this case, you'd be wasting resources anyway by sending a response that won't even be seen by the end user. If you do a redirect, you shouldn't output anything anyway, and you should exit the script after doing one. (via the exit keyword).
So, case-in-point, you can't have any script output before the redirect. You can't have any white space or HTML or anything at all before the opening <?php delimiter.
You can also control output using PHP's output buffer functions. See:
http://www.php.net/outcontrol
These functions allow you to write output to a buffer so that it isn't sent right away. You consume more resources this way, but it allows you to work around errors like the one you saw.
HTH!
Regards,
Rich
--
Author,
Beginning CSS: Cascading Style Sheets For Web Design
CSS Instant Results
http://www.catb.org/~esr/faqs/smart-questions.html