To use sessions and modify the HTTP headers, you can't send HTML data before all of that is done, as it will send the HTTP headers and you can't change them.
To do this, put the HTML after your '?>' inside PHP, and echo it in an if() statement. Don't leave ANYTHING outside '<?PHP ?>'... not even a space.
EDIT: Also, in $sql you have "$POST[username]" ... this is definitely not how to reference indeces in arrays. If you MUST leave the array inside a double quoted string like that, surround it in braces and use quotes for the index name, e.g. "{$POST['username']}". The index name is a string, unless you intentionally defined a constant called "username", and strings are delimited by quotes. It's easiest (and better, IMHO) to simply concatenate the string and the array, e.g.
$test = 'Your name is: ' . $_POST['username'] . '!';
EDIT2: In fact, you've used the $_POST[username] reference in many places in your script... I bet that's one reason for the header error, because PHP is probably trying to throw out an E_NOTICE at you for the erraneous syntax.