It works for me, although I had to remove your SQL code cos I don't have your DB. I would guess, then, that your query is failing. Maybe you could try checking that you indeed have one result only from the db with mysql_num_rows().
You are using the mod_php version of PHP aren't you? The cgi version does not work with apache authentication.