You aren’t returning a result, you’re returning a query resource:
function checkMail($email){
$email = mysql_real_escape_string($email);
$sql = "SELECT COUNT(*) as emailCount FROM users WHERE email="$email"";
$query = mysql_query($sql) or die(mysql_error()); // show error if one happens
return mysql_fetch_assoc($query);
}
This will return an associative array containing your results (if it succeeds), and you should be able to access your count by:
$res = checkMail('[email protected]');
$count = $res['emailCount'];
Side note:
mysql
functions are deprecated, you should use mysqli
or PDO
syntax:
https://stackoverflow.com/a/13944958/2812842
solved Doesn’t work “SELECT COUNT(*) FROM…” in PHP script