Rather than running the userid and password past mysql at each page, you should do this once in the login page and if successful register a session var like user_in = 'true'. Then check for this var in your secure pages:
if (!$HTTP_SESSION_VARS['user_in']) {
header ('Location: nogoodnik.php');
}
More secure and efficient.
setic