if!isset multiple OR condition

Dep*_*ify 12 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!";

    }
    ?>
Run Code Online (Sandbox Code Playgroud)

我也试过两次使用!isset.

Die*_*lló 19

isset() 接受的不仅仅是一个参数,所以只需要传递尽可能多的变量来检查:

<?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!";   
    }
?>
Run Code Online (Sandbox Code Playgroud)

您也可以使用empty()它,但它一次不接受多于一个变量.


小智 10

这就是我解决这个问题的方法:

$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!";
}
Run Code Online (Sandbox Code Playgroud)