Php 如果!isset多个或多个条件

Php 如果!isset多个或多个条件,php,Php,我不能让它为我的生活工作,它是PHP <?php if (!isset($_POST['ign']) || ($_POST['email'])) { echo "Please enter all of the values!"; } else { echo "Thanks, " . $_POST['ign'] . ", you will recieve an email when the site is complete!"; }

我不能让它为我的生活工作,它是PHP

<?php
 if (!isset($_POST['ign']) || ($_POST['email'])) {

  echo "Please enter all of the values!";
    }

 else {

   echo "Thanks, " . $_POST['ign'] . ", you will recieve an email when the site is         complete!";

    }
    ?>

我也试过使用!i设置两次。

接受的不仅仅是一个参数,因此只需传递您需要检查的尽可能多的变量即可:

<?php
    if (!isset($_POST['ign'], $_POST['email'])) {
        echo "Please enter all of the values!";
    }else{    
        echo "Thanks,". $_POST['ign'].", you will receive an email when the site is complete!";   
    }
?>

您也可以使用,但它一次只能接受一个变量

 isset($_POST['ign'],$_POST['email']));

然后检查空值。

我知道的最简单的方法:

<?php
if (isset($_POST['ign'], $_POST['email'])) {//do the fields exist
    if($_POST['ign'] && $_POST['email']){ //do the fields contain data
        echo ("Thanks, " . $_POST['ign'] . ", you will recieve an email when the site is complete!");
    }
    else {
        echo ("Please enter all of the values!");
    }
}
else {
    echo ("Error in form data!");
}
?>

编辑:更正代码,分别显示表单数据和空值错误


说明:第一个if语句检查提交的表单是否包含两个字段:ign和email。这样做是为了阻止第二条if语句抛出错误(消息将打印到服务器日志中),以防根本没有传入ign或email。第二条if语句检查ign和email的值,看它们是否包含数据。

我就是这样解决这个问题的:

$expression = $_POST['ign'] || $_POST['email'] ;
if (!isset($expression) {
    echo "Please enter all of the values!";
}
else {
     echo "Thanks, " . $_POST['ign'] . ", you will recieve an email when the site is                              
              complete!";
}
您可以尝试以下代码:

<?php
    if(!isset($_POST['ign'], $_POST['email'])) {
        echo "Please enter all of the values!";
    } else {
        echo "Thanks, " . $_POST['ign'] . ", you will receive an email when the site is complete!";
    }
?>

试试这个:

<?php
 if (!isset($_POST['ign']) || isset($_POST['email'])) {
  echo "Please enter all of the values!";
    }
 else {
   echo "Thanks, " . $_POST['ign'] . ", you will recieve an email when the site is         complete!";
    }
    ?>

使用POST时,请使用
empty()
。因为当表单发送数据时。空输入为异步null! 最好的办法是:

 if ((!isset($_POST['ign']) || empty($_POST['ign'])) &&
     (!isset($_POST['email']) || empty($_POST['email'])) {
对!!很难看

因此,您可以使用:

<?php
 if ( checkInput($_POST['ign']) || checkInput($_POST['email']) ) {

  echo "Please enter all of the values!";
    }

 else {

   echo "Thanks, " . $_POST['ign'] . ", you will recieve an email when the site is         complete!";

    }

 function checkInput($input){
     return ( !isset($input) || empty($input) );
 }
?>


您确定要检查或调节吗?如果两个条目都是必需的,您应该使用,我从输出文本中了解到,用户正在寻找一种检查所有必需字段的方法。当然,这可能会让人困惑,因为问题的标题是。isset()只适用于变量,因为传递任何其他内容都会导致解析错误。您正在传入一个计算结果为布尔值的表达式。换句话说,这不符合人们的想法。这起作用了,但我不明白为什么。。。第一个if语句是否已经覆盖了第二个if语句?@user1138090第一个if验证表单数据是否包含这两个字段。第二个if验证字段是否为空。如果下面的答案之一回答了您的问题,您应该接受它作为答案!:)如果(!isset($\u POST['ign'],$\u POST['email'])应该是if(!isset($\u POST['ign'],$\u POST['email']),则在if(!isset($\u POST['ign'],$\u POST['email'])的末尾缺少额外的圆括号{此解决方案是在3年前由投票最多的答案Diego发布的。这是否真的有效?如果只满足一个参数,它将回显所有值?请正确设置代码格式以确保可读性。
<?php
 if ( checkInput($_POST['ign']) || checkInput($_POST['email']) ) {

  echo "Please enter all of the values!";
    }

 else {

   echo "Thanks, " . $_POST['ign'] . ", you will recieve an email when the site is         complete!";

    }

 function checkInput($input){
     return ( !isset($input) || empty($input) );
 }
?>