搜索表单无效

时间:2016-12-10 11:12:50

标签: php mysql

我的搜索表单无效。它仅在我删除“搜索栏”时才有效。叫'搜索'因为我还有几个下拉菜单,用户可以从表中获取详细信息。我简单地添加了搜索'因此用户可以直接找到具体信息。但是,当我添加了搜索'吧,那它不起作用。

的index.php

     <form name="formbrwse" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="multipart/form-data">
         <input type="text" name="search">
<td>
<input type="image" name="searchbtn" id"searchbtn" src="searchbtn.fw.png"
width="166" height="38"></td>

的search.php

if(isset($_POST['searchbtn_x'])&&($_POST['searchbtn_x']!='')&&isset($_POST['search'])&&($_POST['search']!='')){
$search=isset($_POST['search'])?$_POST['search']:"";
$search=preg_replace("#[^0-9a-z]i#","",$search);
$category=isset($_POST['category'])?$_POST['category']:"";
$location=isset($_POST['location'])?$_POST['location']:"";
$name_ddasr=isset($_POST['name_ddasr'])?$_POST['name_ddasr']:"";
$opt=isset($_POST['opt'])?$_POST['opt']:"";
//dropdown menu below
if(isset($_POST['category'],$_POST['location'],
$_POST['name_ddasr'],$_POST['opt'])){
if($_POST['search']!=''&&$_POST['category']=='All Categories'&&$_POST['location']
=='Entire Place'&&$_POST['name_ddasr']=='For sale'&&$_POST['opt']=='vrecent'){
//DDmenu comparing ends here    
$advert = "SELECT * FROM usertable WHERE adtitle LIKE '%$search%' AND 
dcrptn LIKE '%$search%' AND optionsalerent='For sale'";
$result=$conn->query($advert);
}}}

1 个答案:

答案 0 :(得分:0)

'For sale'后缺少双引号。它应该是'For sale'";

$advert = "SELECT * FROM usertable WHERE adtitle LIKE '%$search%' AND 
dcrptn LIKE '%$search%' AND optionsalerent='For sale';