Well, I'm not sure 'cause my eyeballs can take only so much, but it looks like you don't have a closing curly brace ( } ) to match the opening curly brace ( { ) in this line:
while ($line = mysql_fetch_array($result)) {
That sort of thing is pretty much the gist of the thread I linked to.