php关键字搜索不起作用
问题描述:
我想通过使用我创建的搜索引擎检索数据库中的数据。php关键字搜索不起作用
它将搜索关键字从testseach.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“;}}}>
我敢肯定,我的数据库连接是否正常工作,我不看我的代码中任何错字
谁能告诉我什么是我的问题吗?。?
答
有一些错误
1)$ query = mysql_query(“SELECT * FROM countries
”,$ connection)or die(“could not search!”);
在的mysql_query添加连接可变
请参阅语法按照PHP文档
2)使用$计数= mysqli_num_rows($查询);为原料GET数量,但您使用mysql_num_rows代替mysqli_num_rows
OR
请检查PHP版本,并使用MySQL或mysqli的 请也因为这可能会导致问题的类型也
是兼容此答案可能对您有所帮助。
这意味着PHP甚至没有运行。但是,您提供的代码中存在许多基本错误,例如'