First of all, always enclose your php/html code with [php] and [/php] tags.
Second, If you have THAT much code to share, please attach it so that people don't have to wade through it all just to see the responses.
Third, please don't IM me just to tell me to come look at your post. That is almost as bad as IMing me with your question directly. I will look at it when I am ready to, ok?
Your problem is with these lines:
<?php if ($fail == 1) {
echo '$error1'; ?>
Can you see what you did?
You failed to close your if() statement with a curly brace ( } ). Put it in, or remove the opening brace, since your if () statement is only one line.
Once that's fixed, you will also have a problem with your echo statement. Because you used single quotes, "$error1" will be echoed to the screen instead of the contents of $error1. Remove the quotes and you should be fine.