gpt4 book ai didi

php - 我的 PHP 搜索功能没有输出数据

转载 作者:行者123 更新时间:2023-11-29 13:12:08 24 4
gpt4 key购买 nike

所以我正在尝试创建一种搜索我的网站的方法。我在索引页上创建了一个搜索栏。您可以在这里找到此页面:http://seersvillage.com/v1.2/

我的搜索表单如下所示:

        <form method="post" action="search.php">
<input type="text" name="search" class="search" value="Skeleton" onFocus="this.value=''">
</form>

我附加了一个functions.php 文件,该页面也连接到我的mysql 数据库。我已经准备好了可供阅读/搜索的内容。

这是我在functions.php上的搜索功能:

function doSearch() {
$output = '';
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preg_replace ("#[^0-9a-z]#i","",$searchq);

$query = mysql_query("SELECT * FROM entries WHERE name LIKE '%$searchq%' or description LIKE '%$searchq%' or content LIKE '%$searchq%'") or die("Could not search");
$count = mysql_num_rows($query);
if($count == 0) {
$output = 'there was no search results!';
} else {
while($row = mysql_fetch_array($query)) {
$eName = $row['name'];
$eDesc = $row['description'];
$eCont = $row['content'];
$id = $row['id'];

$output .= '<div>'.$eName.' '.$eDesc.'</div>';
}
}
}

}

我的 search.php 上唯一的内容(不包括您常用的 html 布局)如下:

<?php

include('includes/functions.php');

if(!isset($_POST['search'])) {
header("Location:index.php");
}

?>

以及标签中的更下方。

<?php print("$output");?>

现在我对 PHP 和 MySQL 还很陌生。然而,我的 error.log 文件中没有收到任何错误,这使得首次使用时进行故障排除有点困难。有什么建议么?我确信这是一个非常简单的错误,可能只是拼写错误,但我就是看不到它。

最佳答案

您的 php.ini 文件似乎已设置为不显示错误。在代码开头添加这些代码行并重试:

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>

关于php - 我的 PHP 搜索功能没有输出数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21948099/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com