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

前端 未结 10 1205
离开以前
离开以前 2021-02-03 10:49

I have this query to use in PHP:

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

When I use e

10条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-03 11:04

    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);
    

提交回复
热议问题