エラー文:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/testsite/search.php on line 33

何が原因でしょうか?

<html>
<head>
</head>
<body>
    <center>
        <form method="get" action="search.php">
            <input type="text" name="search">
            <input type="submit" name="submit" value="search database">
        </form>
    </center>
<hr />

<?php

if(isset($_REQUEST['submit'])){
    $search = $_GET['search'];
    $terms = explode(" ", $search);
    $query = "SELECT * FROM users WHERE";

    $i = 0;
    foreach ($terms as $each) {
        $i++;
        if ($i == 1) {
            $query .= "name LIKE '%each%'";
        } else {
            $query .= "OR name LIKE '%each%'";
        }
    }
    mysql_connect("localhost","root","") or die("problem with connection...");
    mysql_select_db("testsite");

    $query = mysql_query($query);
    $num = mysql_num_rows($query);

    if($num > 0 && $search!=""){
        while ($row = mysql_fetch_assoc($query)) {
            $id = $row['id'];
            $name = $row['name'];
            $email = $row['email'];
            $password = $row['password'];
            echo "$name<br />$email<br />";
        }
    } else {
        echo "No results found";
    } mysql_close();
} else {
    echo "Please type any word...";
}

?>
</body>
</html>