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

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

<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'/>
<hr />
 $k = $_GET['k'];

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

 foreach ($terms as $each){

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

 // connect


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


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

 // disconnect




please help me debugging this one

Recommended Answers

good catch..

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

Jump to Post

All 2 Replies

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.

good catch..

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.