dpg98445 2014-02-09 19:44
浏览 110
已采纳

无法从SQL查询中获取COUNT结果

When I run this code it only ever returns 0, even when I have the right information. I have checked in the database the same query and it returns a count of one when I have the correct info but this always returns 0.

$query = 'SELECT COUNT(*) FROM user WHERE UserName = "$username"  AND UserPass = "$password"';

    $result = mysqli_query($con, $query);

    $hello = mysqli_fetch_array($result); echo $hello[0]; exit;
  • 写回答

2条回答 默认 最新

  • dongnigeng1295 2014-02-09 19:49
    关注

    change to

     $query = 'SELECT COUNT(*) FROM user WHERE UserName = "' . $username . '" AND UserPass = "'. $password .'"';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?