【发布时间】:2016-11-11 11:22:26
【问题描述】:
我想使用我创建的搜索引擎检索数据库中的数据。
它将搜索关键字从 testeach.php 传递给 searchTitle.php。
这是我的测试 seach.php 代码
>!DOCTYPE html>
<html>
<head><title></title>
</head>
<body>
<form action="searchTitle.php" method="GET" class="formright">
<input type="text" name="keywords" placeholder="Search">
<input type="submit" value="search">
</form>
</body>
</html>
这是我的 searchtitle.php,它传递了来自 testsearch 的关键字。
<? php
require_once 'database_conn.php'
//collect search title
if(isset($_GET['keywords'])){
$searchq = $_GET['keywords'];
$searchq = preg_replace("#[^a-z]#i" , "", $searchq);
$query = mysql_query("SELECT eventTitle FROM te_events where eventTitle LIKE '%searchq%'") or die("could not search!");
$count = mysqli_num_rows($query);
if($count==0){
echo "<p>There was no search result!</p>\n";
}
else{
while ($row = mysql_fetch_assoc($query)){
$title = $row['eventTitle'];
$id = $row['eventID'];
echo "<p>$title</p>\n";
}
}
}
?>
但是,它显示了这个错误
没有搜索结果! \n"; } else{ while ($row = mysql_fetch_assoc($query)){ $title = $row['eventTitle']; $id = $row['eventID']; echo " $title
\n"; } } } ?>
我很确定我的数据库连接正常,并且我的代码中没有看到任何拼写错误。
谁能告诉我我的问题是什么?
【问题讨论】:
-
这意味着 PHP 甚至没有运行。但是您提供的代码中有许多基本错误,例如
<? php我预计会出现语法错误,几乎可以肯定您没有正确设置 PHP。
标签: php