【发布时间】:2018-12-20 07:22:53
【问题描述】:
当我只按关键字搜索时,这个搜索引擎应该会给我一个输出。当我只搜索状态时,它也应该允许在给出状态和关键字时进行搜索。如果没有给出任何内容,它应该获取表中的所有属性,但它给了我一个错误:
致命错误:未捕获的错误:调用成员函数 bindValue() on C:\xampp\htdocs\accommoport\sch\search.php:72 中的字符串 堆栈跟踪: 0)
如何完成这个?
$keyword= $_GET["keyword"];
$stmt_search = "SELECT * FROM houses WHERE
(property_city LIKE :param
OR property_state LIKE :param
OR property_address LIKE :param
OR property_name LIKE :param)
-- AND property_status LIKE :status
";
$stmt_search->bindValue(':param', '%'.$keyword.'%');
if($_GET['search_status']!='')
{
$status =$_GET["search_status"];
$stmt_search .= "AND property_status LIKE :pstatus";
$stmt_search->bindValue(':pstatus', $status);
}
$stmt=$conn->prepare($stmt_search);
$stmt->execute();
if($stmt->rowCount() > 0){
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
# code...
?>
【问题讨论】:
-
你不是
prepare你的查询,你只是想在一个字符串上调用bindValue(如错误所说)...... -
首先需要准备一个语句,然后才能绑定参数。此外,您的参数命名似乎非常不一致。