php - MySQL搜索查询错误

标签 php mysql

我正在尝试创建一个表单,允许用户使用 field 和类别字段搜索事件,这些字段被编写为下拉框和价格,最后按事件标题,如输入关键字时通过代码所示它与数据库上的字段匹配,如果在任一搜索字段上进行了任何匹配,它应该输出该事件的所有相关信息,但无论我在搜索字段中输入什么,它似乎都会输出数据库中的每个事件。

数据库:http://i.imgur.com/d4uoXtE.jpg

HTML 表单

    <form name="searchform" action ="PHP/searchfunction.php" method = "post" >
<h2>Event Search:</h2>
Use the Check Boxes to indicate which fields you watch to search with
<br /><br />
<h2>Search by Venue:</h2>

<?php
echo "<select name = 'venueName'>";
$queryresult2 = mysql_query($sql2) or die (mysql_error());
while   ($row = mysql_fetch_assoc($queryresult2))  {
echo "\n";
$venueID = $row['venueID'];
$venueName = $row['venueName'];
echo "<option value = '$venueID'";
echo ">$venueName</option>";
}# when the option selected matches the queryresult it will echo this

echo "</select>";
mysql_free_result($queryresult2);
mysql_close($conn);
?>
<input type="checkbox" name="S_venueName">
<br /><br />
<h2>Search by Category:</h2>
<?php
include 'PHP/database_conn.php';

$sql3 ="SELECT catID, catDesc
FROM te_category";

echo "<select name = 'catdesc'>";
$queryresult3 = mysql_query($sql3) or die (mysql_error());
while   ($row = mysql_fetch_assoc($queryresult3))  {
echo "\n";
$catID = $row['catID'];
$catDesc = $row['catDesc'];
echo "<option value = '$catID'";
echo ">$catDesc </option>";
}

echo "</select>";
mysql_free_result($queryresult3);
mysql_close($conn);
?>
<input type="checkbox" name="S_catDes">
<br /><br />

<h2>Search By Price</h2>
<input type="text" name="S_price" />
<input type="checkbox" name="S_CheckPrice">
<br /><br />

<h2>Search By Event title</h2>
<input type="text" name="S_EventT" />
<input type="checkbox" name="S_EventTitle">
<br /><br />
<input name="update" type="submit" id="update" value="Search">

searchfunction.php 文件

<?php
$count = 0;
include 'database_conn.php';


$venuename = $_REQUEST['venueName']; //this is an integer
$catdesc = $_REQUEST['catdesc']; //this is a string
$Price = $_REQUEST['S_price'];
$EventT = $_REQUEST['S_EventT'];



$sql = "select * FROM te_events WHERE venueID LIKE '%$venuename%' OR catID LIKE '%$catdesc%' OR          eventPrice LIKE '%Price%' OR eventTitle LIKE '%$EventT%'";

$queryresult = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_assoc($queryresult))
{
    echo $row['eventTitle'];
    echo $row['eventDescription'];
    echo $row['venueID'];
    echo $row['catID'];
    echo $row['eventStartDate'];
    echo $row['eventEndDate'];
    echo $row['eventPrice'];
}

mysql_free_result($queryresult);
mysql_close($conn);

?>

最佳答案

查询应该是 $sql =“从te_events中选择* WHERE (venueID LIKE '%$venuename%' 或类似“%$catdesc%”的 catID 或者 eventPrice LIKE '%$Price%' 或者类似“%$EventT%”的事件标题) ;

关于php - MySQL搜索查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23503991/

相关文章:

javascript - 在表单中添加数据库中的下拉列表

wordpress - nginx Wordpress URL重写

php - 防止时段被重复预订

php - 通过更新多行删除不需要的内容

php - 使用 PHP/MySQL 的分层递归菜单

php - Paypal API v2 响应指定的资源不存在

javascript 不转换特殊字符

php - 插入选定的数据作为外键和 SQLSTATE[23000] : Integrity constraint violation: 1048

mysql - 从数据库中检索数据并将其发送到laravel中的ajax

mysql - Group by with sum 不返回正确的结果