"Header already sent" basically means that the Web server has sent HTML to the browser already.
It's something you can't do twice. You're no longer connected to the Web server, and all rendering is done.
This is the HTTP equivalent of missing the boat.
You can get around the problem you're having, by buffering all output and getting it all out at once.
Put the following line at the top of your script, before any echos, prints, or raw HTML, (including any "blank" lines outside of your php tags!):
ob_start();
...and this line at the end, after all echos, prints, et al.
ob_end_flush();
So, you're putting these lines just after and before your php tags, repsectively:
<?php
on_start();
//all your code here
ob_end_flush();
?>
If this doesn't apprear to work, there's some HTML or a blank line outside of your php tags. Delete them and it will work.
There's one variation on this, which is to use ob_end_clean(), which does the same thing as ob_end_flush() but also deletes everything in the buffer (if your "data" is already on-screen, do you need it in memory? You may or may not.)
The only thing you could do to prevent this from working is to try to use both a POST and a session at the same time...that sort of thing.
I think this will eliminate the problem.