【发布时间】:2011-08-25 18:59:04
【问题描述】:
我在我的主页上进行了大量搜索,当用户在文本字段中键入并单击提交时,我希望我的数据库中的结果出现在另一个站点上,在这种情况下是“searchresults.php”。在这种情况下,“really.html”是我的主页。
这是我的代码:
我做错了什么?
Really.html
<center>
<form action="searchresults.php" method="post">
<input type="text" size="35" value="Job Title e.g. Assistant Manager"
style="background- color:white; border:
solid 1px #6E6E6E; height: 30px; font-size:18px;
vertical-align:9px;color:#bbb"
onfocus="if(this.value == 'Job Title e.g. Assistant Manager'){this.value =
'';this.style.color='#000'}" />
<input type="text" size="35" value="Location e.g. Manchester"
style="background- color:white; border:
solid 1px #6E6E6E; height: 30px; font-size:18px;
vertical-align:9px;color:#bbb"
onfocus="if(this.value == 'Location e.g. Manchester'){this.value =
'';this.style.color='#000'}" />
<input type="image" src="but.tiff" alt="Submit" width="60">
</form>
搜索结果.php
<html>
<body>
<?php
if(strlen(trim($_POST['search'])) > 0) {
//all of your php code for the search
$search = "%" . $_POST["search"] . "%";
$searchterm = "%" . $_POST["searchterm"] . "%";
mysql_connect ("", "", "");
mysql_select_db ("");
if (!empty($_POST["search_string"]))
{
}
$query = "SELECT name,location,msg FROM contact WHERE name LIKE '$search' AND
location LIKE '$searchterm'";
$result = mysql_query ($query);
if ($result) {
while ($row = mysql_fetch_array ($result)) {
echo "<br>$row[0]<br>";
echo "$row[1]<br>";
echo "$row[2]<br>";
}
}
}
?>
</body>
</html>
谢谢!
【问题讨论】:
-
什么不起作用?你遇到了什么错误?
-
我没有收到任何错误,它只是空白,searchresults.php 页面上没有任何内容
-
我是否必须拆分php代码并将一些放入really.html中?
-
要么检查错误日志,要么将显示错误设置为 1:
ini_set( 'display_errors',1); -
@James:启用 PHP 的错误报告。你会发现页面有错误。