Displaying form errors and other errors can be a tedious task; one easy way is to use this javascript code:
(Output this from your script)
<html><script>alert("error message");history.go(-1);</script></html>
Then you can just exit your script. It's not the prettiest, but suffices in many cases. This will pop up an alert window, and take the user back to the form after they click "Ok".