<?php
mysql_connect("localhost", "root", "");
mysql_select_db("database360");
?>
<!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>
<center>
<h1 style="color:#069; font-size:36px;">TEST ENGINEenter code here</h1>
<form action="./result.php" method="get">
<input type="text" name="input" size="50" <?php echo $_GET['input']; ?> />
<input type="submit" value="search"/>
</form>
</center>
<hr/>
<?php
$input = $_GET['input'];
$terms = explode(" ", $input);
$query = "SELECT * FROM search WHERE";
foreach ($terms as $each){
$i++;
if ($i == 1)
$query .= "keywords LIKE '%each%' ";
else
$query .= "OR keywords LIKE '%each%' ";
}
//connect to database
mysql_connect("localhost", "root", "");
mysql_select_db("database360");
$query1 = mysql_query($query);
$numrows = mysql_num_rows($query1);
if ($numrows > 0){
while ($rows=mysqlfetch_assoc($query1)){
$id = $row['id'];
$title = $row['title'];
$description = $row['description'];
$keywords = $row['keyword'];
$link = $row['link'];
echo "<h2><a href='$link'>$title</h2>
$description<br></br>";
}
}
else echo "No results found for \"<b>$input</b>\"";
//disconnect
mysql_close();
?>
</body>
</html>
错误信息是:
注意:未定义变量:第 33 行 C:\xampp\htdocs\SEARCH\result.php 中的 i
警告:mysql_num_rows() 期望参数 1 是资源,布尔值在第 46 行的 C:\xampp\htdocs\SEARCH\result.php 中给出 没有找到“联系人”的结果