mysql - php - Search query -


i built simple search query.when user fills input , sends , creates search query gets database information matches keywords given.

but when send keywords, gives me error :

warning: mysql_num_rows() expects parameter 1 resource, boolean given in c:\xampp\htdocs\www.c++.com\search-query.php on line 59

no results found "c++"

my php file looks :

    <form id="search" method="get" action="search-query.php">         <input type="text" name="keywords" placeholder="search..." />         <input type="submit" value="go" style="margin:10px" />     </form> 

and search query script :

<form id="search" method="get" action="search-query.php">      <input type="text" name="keywords" placeholder="search..." value="<?php echo $_get['keywords']; ?>" />      <input type="submit" value="go" style="margin:10px" /> </form>           <div>             <?php                 $i = 0;                 $keywords = $_get['keywords'];                 $terms = explode(" ",$keywords);                 $query = "select * search ";                  foreach ($terms $term){                     $i++;                                       if ($i == 1)                         $query .="keywords '%$term%' ";                     else                         $query .= "or keywords '%$term%' ";                 }                  //connect                  mysql_connect("localhost", "root", "");                 mysql_select_db("search");                  $query = mysql_query($query);                 $numrows = mysql_num_rows($query);                 if($numrows > 0){                      while ($row = mysql_fetch_assoc($query)){                         $id = $row['id'];                         $title = $row['title'];                         $description = $row['description'];                         $key = $row['keywords'];                         $link = $row['link'];                     }                      echo "<h2><a href='$link'>$title</a></h2>                     $descripton";                  } else echo "no results found \"<b>$keywords</b>\"";                  //disconnect                 mysql_close();               ?>         </div> 

i don't know why $query variable boolean type .if anybode can me i'll thankfull.

edit : did changes, changed mysqli have error: warning: mysqli_num_rows() expects parameter 1 mysqli_result, boolean given in c:\xampp\htdocs\www.c++.com\search-query.php on line 60 still $query boolean type

the script :

   <?php         $i = 0;         $keywords = $_get['keywords'];         $terms = explode(" ",$keywords);         $query = "select * search ";          foreach ($terms $term){             $i++;                               if ($i == 1)                 $query .="keywords '%$term%' ";             else                 $query .="or keywords '%$term%' ";         }          //connect          $link = mysqli_connect("localhost", "root", "", "search");         $query = mysqli_query($link, $query);         $numrows = mysqli_num_rows($query);         if($numrows > 0){              while ($row = mysqli_fetch_assoc($query)){                 $id = $row['id'];                 $title = $row['title'];                 $description = $row['description'];                 $key = $row['keywords'];                 $link = $row['link'];             }              echo "<h2><a href='$link'>$title</a></h2>             $descripton";          } else echo "no results found \"<b>$keywords</b>\"";          //disconnect         mysqli_close($link);       ?> 

your proble line:

$query = mysql_query($query); 

the explaination lies in php documentation:

for select, show, describe, explain , other statements returning resultset, mysql_query() returns resource on success, or false on error.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -