0

I m having this problem while executing search

Notice: Undefined variable: i in D:\xampp\htdocs\search.php on line 23

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\search.php on line 35

.

here is my source code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>search engine</title>
</head>

<body>
<h2>search engine</h2>
<form action='./search.php' method='get'>
<input type='text' name='k' size='100' value='<?php echo $_GET['k']; ?>' />
<input type='submit' value='search'/>
</form>
<hr />
<?php
 $k = $_GET['k'];

 $terms = explode(" ",$k);
$query="SELECT * FROM search WHERE";

 foreach ($terms as $each){
 $i++;

 if ($i==1)
 $query.="keywords LIKE '%$each%''";
 else
 $query.="OR keywords LIKE '%$each%''";
 }

 // 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'];
 $id=$row['title'];
 $id=$row['description'];
 $id=$row['link'];

 echo"<h2><a href='$link'>$title</a></h2>
 $description<br />";

 }
 }

 else
 echo"NO results found for \<b>$k</b>\"";


 // disconnect
 mysql_close();


?>



</center>
</body>

</html>

please help me debugging this one

Edited by diafol: apply code tags

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by |-|x
0

Where you have //connect place print_r($query); exit; and check if the query has a regular structure, probably there is something wrong with the loop above, I don't see any space beetween WHERE and conditions.

1

good catch..

also looks like there might be too many closing quotes on '%$each%''"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.