Warning: mysql_num_rows() expect parameter 1 to be resource, boolean given error

Asked 1 years ago, Updated 1 years ago, 38 views

Error statement:
Warning: mysql_num_rows() expectations parameter 1 to be resource, boolean give in/Applications/XAMPP/xamppfiles/htdocs/testsite/search.phponline33

What is the cause?

<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 of >

<?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>

php mysql

2022-09-30 19:35

1 Answers

SQL build seems to be failing.

This is

$query="SELECT* FROM users WHERE";

Place half-width space behind WHERE

$query="SELECT* FROM users WHERE";


2022-09-30 19:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.