Why do I get this error: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given?

I keep getting the following error when I'm trying to log in:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\school\index.php on line 49

This is the code:

extract($_POST);
$query = "SELECT * FROM `login` WHERE `username` = '$username' AND `password` = '$password' AND `role` = 'admin' ";
$result = mysqli_query( $con, $query);
$count = mysqli_num_rows($result);
if ( $count == 0)
{
    echo " <script> $('#incorrect').show(); </script> ";
}
else
{
    while( $row = mysqli_fetch_assoc( $result))
    {
        $username = $row['username'];
        $role = $row['role'];
    }
    $sess_array = array('username' => $username, 'role' => $role);
    $_SESSION['login_admin'] = $sess_array;
    header('location: welcome.php');
}