mysql查询WHERE子句中未分配的php变量

mysql查询WHERE子句中未分配的php变量,php,mysql,Php,Mysql,我在WHERE子句中有一个带有php变量的查询。但如果变量未赋值,它不会返回结果 $customer = isset($_REQUEST['customer'])?$_REQUEST['customer']:''; $territory = isset($_REQUEST['territory'])?$_REQUEST['territory']:''; $status = isset($_REQUEST['status'])?$_REQUEST['status']:''; $getOrder

我在WHERE子句中有一个带有php变量的查询。但如果变量未赋值,它不会返回结果

$customer = isset($_REQUEST['customer'])?$_REQUEST['customer']:'';
$territory = isset($_REQUEST['territory'])?$_REQUEST['territory']:'';
$status = isset($_REQUEST['status'])?$_REQUEST['status']:'';

$getOrder = "SELECT * FROM order WHERE Customer = '$customer' AND Territory = '$territory' AND Status = '$status'";
$getOrderQuery = mysql_query($getOrder);
while($iRow = mysql_fetch_array($getOrderQuery))
{ .... }

如果分配了这三个变量,它将返回结果。我需要做什么才能使查询返回结果,即使变量为空

我不能对你的帖子发表评论,但我可以留下答案

尝试
echo$getOrder
确保变量符合预期,然后使用MySQL客户端或phpMyAdmin直接在数据库上执行查询

此外,您应该转义变量,因为您对SQL注入攻击很有价值。我喜欢使用

你也可以根据下面的评论来尝试

SELECT * FROM order 
WHERE IFNULL(Customer, '') IN('$customer', '') AND IFNULL(Territory,'') IN('$territory','') AND IFNULL(Status, '') IN('$status','')";

嗯。在考虑这个问题之前,切换到mysqli或PDO并使用参数化查询。只需在语句后面添加一个
或Customer='
?如果我使用或而不是,查询将返回不正确的结果。我要说的是执行类似于
的操作,从(Customer='$Customer'或Customer='')和(Territory='$Territory'或Territory='')和(Status='$Status'或Status='');
我认为want OP希望返回结果,即使变量为空。