I think you have got your problem solved. I wanted to mention something about security. Try never to use a query like this:
"SELECT * FROM users WHERE username='$username' AND password='password' "
because it is vulnerable to a term called "SQL injection". one can use something like this.
suppose user "admin" is present in the database. a hacker only needs to provide username and password like this:
username="admin"
password=" ' or ''=' "
put this in the query and your query will be like this:
"SELECT * FROM users WHERE username='admin' AND password='' '' or ''='' "
and since it is an OR case and ''='' is always true the hacker can pass the login page.
Good luck