Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

php - How do I count query result rows?

What should I replace 'CODE TO VERIFY IF QUERY RESULT ROW IS = 1' for?
I've tried many ways using num_rows but it won't work.

My PHP code:

    $con=mysqli_connect("localhost","mbrconsu_un394x","y1cz9,rd+hf6","mbrconsu_mmx");

    if (mysqli_connect_errno($con))
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $usuario = $con->real_escape_string($_GET['usuario']);
    $senha = $con->real_escape_string($_GET['senha']);

        $query = mysqli_query($con, "SELECT * FROM 'login' WHERE usuario = '$usuario' AND senha='$senha'");

        if(CODE TO VERIFY IF QUERY RESULT ROW IS = 1){
            while($row = mysqli_fetch_assoc($query)){
                $db_username = $row['usuario'];
                $db_password = $row['senha'];
            }
            if($usuario == $db_username && $senha == $db_password){
                return true;
            }
            } else {
            return false;
        }

    mysqli_close($con);
?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
$query->num_rows;

or

mysqli_num_rows($query);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...