near the top of the page, you have a comment outside of the php tags
and you have blank lines between the php tags.
These will cause the header function to return the Headers Already sent error message and will cause the redirect to fail.
there cannot be html output and blank lines between php code blocks.