エラー文：  
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>
    
```
CC BY-SA 3.0
2015-07-26T06:21:10.280
12712
2015-08-04T11:23:04.170
7176
question
php mysql
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean givenのエラー
SQLの構築に失敗しているようです。

これを

```

    $query = "SELECT * FROM users WHERE";
    
```

WHEREの後ろに半角スペースを入れてください。

```

    $query = "SELECT * FROM users WHERE ";
    
```
CC BY-SA 3.0
2015-08-04T11:23:04.170
13030
2015-08-04T11:23:04.170
7918
12712
answer