好的,所以我正在尝试为我的网站编写一个小的 PHP 搜索脚本,以便用户可以简单地从艺术家姓名、歌曲名称或城市进行搜索。我的数据库中的表有“城市”、“艺术家”和“城市”。
这是我的表格:
<div id="search">
<form name="search" method="post" action="../searchDb.php">
<input type="text" name="find" placeholder="What are we searching for ?"/> in
<Select NAME="field">
<Option VALUE="artist">Artist</option>
<Option VALUE="song">Song</option>
<Option VALUE="city">City</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>
</div>
如您所见,共有三个 OPTION 值(表中的每一列一个)。这是我的PHP代码:
<?php
$searching = "searching";
$find = "find";
$field = "field";
//this is to make sure the user entered content
if ($searching =="yes")
{
echo "<p><h2>Results</h2></p>";
//if user did not enter anything in the search box, give error
if ($find == "")
{
echo "<p>You forgot to enter a search term</p>";
}
include 'connect.php';
// strip whitespace, non case sensitive
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
//perform search in specified field
$data = mysql_query("SELECT * FROM artists_table WHERE upper($field) LIKE'%$find%'");
//show results
while($result = mysql_fetch_array( $data ))
{
echo $result['artist'];
echo " ";
echo $result['song'];
echo "<br>";
echo $result['city'];
echo "<br>";
echo "<br>";
}
//counts results. ifnone. error
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
//show user what he searched.
echo "<b>Searched For:</b> " .$find;
}
?>
我的connect.php(包括在内)完美运行(我在另一个页面上有相同的文件,没有问题..所以可以肯定地说那不是问题)。
当我进行测试并运行搜索时,它会加载我的 searchDb.php 但没有显示任何内容。只是一个白页...
任何帮助将不胜感激。我不知道为什么或什么不工作......谢谢你们!