This is not returning a result object like you are assuming it should.
I assume the mysql connection is happening in database.php.
You should really be checking for a mysql error after a any query you do. It's a good practice to get into. I would check to see what mysql_query is returning here is some code right from php.net that shows how to check for a query problem
I also want to point out a security hole open for SQL Injection using your method of building the query. You will want to escape that before you just plug username in since you are just plugging that value in from a POST variable.
reference this method built into PHP or switch to use a PEAR Database package.
PHP: mysql_real_escape_string - Manual