thanks for you replies.
I moved the code to the <head> of the document, and still get the same error.
I get the error only when the page is loaded AGAIN, when I submit the form to it.
The solution I see is handling the proccessing of the data in a seperate file, not on the same page with the form, I'll try it.
I used to program in JSP, where you can redirect from anywhere in the HTML.