using select you are not affecting any rows.
You should use mysql_num_rows() on line 22 instead, and you want it == 1 (because each username should only have 1 assciated password, and if you are getting more than 1 you're in trouble.
Also, sanitize your variables (learn about mysql_real_escape_string())