The problem is that you are using
mysql_affected_rows()
with a SELECT query - it is only for queries that modify data like INSERT and UPDATE.
You should be using
mysql_num_rows[
^] to find the number of rows that the SELECT query is returning.
If you visit the page I linked to you will see that the whole family of mysql_* functions are deprecated in the latest version of PHP because there are newer and better interfaces available.
And don't forget to
sanitize your inputs[
^].