查询提交表单后的问题

mengdiQian mengdiQian 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
请问以下这段搜索的代码那边出了错?
当我txtName没有填写内容,提交表单的时候,
sql语句还是只执行最后一个sql语句,即select * from material order by Mat_id,
而我要的效果是它应该执行第一条语句,即select * from material where Mat_name like '%$name%' and Mat_category in ($category)
<form action="?action=search" method="post" name="form1" id="form1">
<p>物料名称:
<input name="txtName" type="text" id="txtName" value="" />
 类别:
<select name="sltCategory" id="sltCategory" onchange="document.getElementById('txtCategory').value=document.getElementById('sltCategory').value">
<option value="">无</option>
<option value="0">耗材</option>
<option value="1">电脑</option>
<option value="2">其他设备</option>
</select><input name="txtCategory" type="text" id="txtCategory" size="10" value="0,1,2" />
   <input name="btnSearch" type="submit" id="btnSearch" value=" 查询 " />
</form>
<?php 
$class = 'action=search&txtName='.$_REQUEST['txtName'].'&txtCategory='.$_REQUEST['txtCategory'];
echo $class."<br>";
if($_REQUEST['txtName']&&$_REQUEST['action']=="search"){
$name = $_REQUEST['txtName'];
$category = $_REQUEST['txtCategory'];
if($name == null){
$sql = "select * from material where Mat_category in ($category) order by Mat_id";
}else
$sql= "select * from material where Mat_name like '%$name%' and Mat_category in ($category)";
}else{
$sql = "select * from material order by Mat_id";
}
echo $sql;

$page = page($db,$sql,5,$class);
while($row=mysql_fetch_array($page[0])){
?>
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
mengdiQian
基础编程 21,889 成员 140,329 内容