To just clarify things in my mind: I take it you're able to fill in the form, submit it, and get back a response saying "Logged in as username:...Please click here"? (That would indicate that the point where the session variable is supposed to be getting set is being reached.) But after that, protected continue to claim you're not logged in?
Can you look at the session file that's created and see what's in it?
There is some possibility that your browser isn't holding on to the session ID. Try a link like
echo "<br><a href='main.php?".SID."'>Please click here to see admin links</a>" to pass the session ID through by hand and see if you get a different result. If the browser isn't accepting cookies and php.ini has session.use_trans_sid turned off then you'll have to pass the session ID around your pages by hand (much as this site does via the "s=" thingy in the URL.
You can probably guess by now that I don't see anything in the code that's obviously wrong...
As a digression:
If you're wanting to see how many username/password combinations are in a database, and that's all - as you're doing here - it's generally a better approach to say
"SELECT COUNT(*) from ..."
This will return a single-row result containing one field - containing the desired number. In other words, you can then get the number of rows by
list($num_rows) = mysql_fetch_row($result)
(With the list there of course to take the first element of the array, not the array itself.)