PHP文件不显示任何错误,但它不显示从MySQL数据库获取的数据。它不是说它无法连接到数据库所以我不知道我这次打破了它:( 搜索引擎
<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)
{
//....
}
//connect
mysql_connect("localhost", "root", "");
mysql_select_db("search");
$query = mysql_query($query);
$num_rows = 0;
if ($query){
while($row = mysql_fetch_assoc($query)){
$id = $row['id'];
$title = $row['title'];
$description = $row['description'];
$k = $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>
</html>
然后我有MySQL数据库设置
答案 0 :(得分:2)
尝试更改
$query = mysql_query($query);
到
$query = mysql_query($query) or die(mysql_error());
看看会发生什么