mysqli_num_rows always returns 0

I am trying out php and database for fun and I would really like to make a basic login system. The connection, query, all that works perfect but when it comes to counting rows it always returns 0, whether there is an user with that name or no. I’ve spent 5 hours on trying to figure this out but nothing seem to work. I just want it to check if there’s an user with that name or no.

code:

  if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} else {
    //check if that name exists
    $exists = mysqli_query($conn, "select * from users where Name='$username'");
    $num_rows = mysqli_num_rows($exists);
    if ($num_rows > 0)  {
        echo "YES: " . $num_rows;
        //header("Location: https://usn-pts.000webhostapp.com/session.php");
    } else {
       // header("Location: https://usn-pts.000webhostapp.com/nouserfound.php");
        echo "NO: " . $num_rows;
    }
}

Instead of

$exists = mysqli_query($conn, "select * from users where Name='$username'");
num_rows = mysqli_num_rows($exists);

Use

num_rows = mysqli_query($conn, "select count(*) from users where Name='$username'");

For this you should have a value in the $username.
Sample Example explained below.

$username = 'Matic';

after this use the code what you have written.Hope it works