user722769 user722769 - 6 months ago 11
SQL Question

How to get the result of a select count(*) query in PHP?

I have this query to use in PHP:

mysql_query("select count(*) from registeredUsers where email=".$_SESSION["username"]);


When I use
echo
to print out the result, nothing gets printed. What exactly is the return value from the above statement?

Answer

Your code doesn't include any fetch statement. And as another answer notes, you need single quotes around $_SESSION["username"].

$result = mysql_query("select count(*) from registeredUsers where email='{$_SESSION['username']}'");

// Verify it worked
if (!$result) echo mysql_error();

$row = mysql_fetch_row($result);

// Should show you an integer result.
print_r($row);
Comments