Looks like there are blank lines between closing php tags:
and opening php tags in the code:
that will cause the headers already sent error.
For the trigger, you are using Current Page submit, try changing that to Button submit pressed, or any form post instead.
NOTE: in the future, please don't paste the page code to your message, instead attach a copy of the php page.