我似乎在下面的代码中遇到了问题。出现的问题是
“注意:未定义的变量:我在第 21 行的 C:\wamp\www\search\search.php 中”
和
“警告:mysql_num_rows() 期望参数 1 是资源,布尔值在第 34 行的 C:\wamp\www\search\search.php 中给出”。
第 21 行是$i++;
第 34 行是$num_rows = mysql_num_rows($query)
<body>
<h2>Search Engine</h2>
<form action='./search.php' method='get'>
<input type='text' name='k' size='50' 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", "password");
mysql_select_db("search");
$query = mysql_query($query);
$num_rows = mysql_num_rows($query);
if ($num_rows > 0){
while($row = mysql_fetch_assoc($query)){
$id = $row['id'];
$title = $row['title'];
$description = $row['description'];
$keywords = $row['Keywords'];
$link = $row['link'];
echo "<h2><a href='$link'>$title</a></h2>
$description<br /><br />";
}
}
else
echo "No results found for \"<b>$k</b>\"";
//disconnect
mysql_close();
?>
</body>
有谁知道如何修理它?