line 53 mysql_close($connect) appears outside the the function login_do
line 203..205 you have an if statement followed by and end / start php tags followed by an else statement
line 214 <?php}?>
line 192 you have a while statement followed by an ?>, some html then <?php, I don't know if this is valid, but it doesn't look right to me
line 384 you have a while statement followed by an end brace with no code to process the while loop
if you get yourself a decent PHP editor these errors would be easily spotted. I used netbeans with the PHP extensions to spot these (well TBH to look where netbeans spotted problems)
I think part of your problem is the style you are using to write the code. Its not the easiest to use. some people recommend using a framework such as smarty to separate the PHP from the HTML.
what I tend to do is create a variable and 'dump' the text into that variable, but in any event the idea is to stop jumping in and out of PHP
there is no need to terminate php between each code block (ferinstance you encapsulate each function with php tags (<?php; ?>), there is no need to do so if as soon as you terminate a php block if the next line starts a new php block. see lines 6..8, 54..56, 65..67 and so on
a suggestion: you need to think about commenting your code so you (or others) can understand the process
also bear in mind that with the way that code is set up you may also be transmitting other characters eg spaces. granted they may not be an issue with most scripts but you do need to be carefull what you send to the browser.
I'd rather be riding on the Tiger 800 or the Norton