You still run the query even if the email address is blank - surely you don’t want to do that?
You’re still using the old-style mysql_query() and similar functions, which have been removed from the latest version of PHP.
I would imagine that if you call the function with the session variable not set, that will give the error message you describe. Even if the session variable is set, you should still check to see whether you got any results from the query before you start to use those results. What are you expecting the function to return if the email address is not in the database?
On the many occasions I have a problem like this I
print_r($swl);
var_dump($data);
Examining the result usually shows what I am doing wrong.
The other option is to run the query from inside phpMyAdmin.
I didn’t see a problem with the query, just that it still runs even if the email address is blank, which presumably will return no results and therefore give the error the OP describes. Potentially calls query on null value, uses results without checking there are any. Or maybe column name is wrong. Can’t guess without more information from OP.