Firstly you can add the password in your sql query:
SELECT * FROM tablename WHERE username = '$name' AND password = '$pass'
Then you just call mysql_num_rows() instead of mysql_fetch_assoc().
mysql_num_rows() returns the number of rows matching your query. If it returns 1, then you have 1 match, and the users name and password is correct. This also saves you extra code such as
if ($user == $userq && $pass == $passq)
as the comparisons were done by the SQL.
ps. You should use strcmp() or '===' to compare strings, not
if ( string1 == string2 )