The error is in this row:
$sql= sprintf ("SELECT * FROM '%s' WHERE Nickname='%s' AND losen='%s';",mysql_real_escape_string($gender), mysql_real_escape_string($nick), mysql_real_escape_string($pass));
You should only use the ' sign in a SQL query for strings. The table name is not considered a string, so you should not use the ' sign there. Instead you can leave it out.
As I said in an earlier post, try to echo the SQL string and use it from PHPMyAdmin. There you will see much better what error you get and where the fault might be. When you have used SQL some time you might even be able to see the problem by just echoing the string out.
Edit: I am curious, why do you use different tables for males and females?