PHP关键字搜索不工作


php keyworks search do not works

我想通过使用我创建的搜索引擎检索数据库中的数据。

它将搜索关键字从testsearch .php传递到searchTitle.php。

下面是测试search .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 =行美元("eventID");Echo " $title

' n";}}} ?>

我很确定我的数据库连接是工作的,我没有看到任何错字在我的代码。

谁能告诉我我的问题是什么?

有一些错误

$query = mysql_query("SELECT * FROM countries ",$connection) or die("could not search!");

在mysql_query中添加连接变量

请参考PHP文档中的语法

2)您使用$count = mysqli_num_rows($query);获取原始数据的数量,但是您使用mysql_num_rows而不是mysqli_num_rows

请检查与mysql或mysqli兼容的php版本也请检查一下,因为这可能会导致类似的问题

这个答案可能对你有帮助。