if !isset multiple OR conditions

前端 未结 8 1217
一整个雨季
一整个雨季 2021-01-04 06:51

I cannot get this to work for the life of me, it is PHP.



        
相关标签:
8条回答
  • 2021-01-04 07:15

    Simplest way I know of:

    <?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!");
    }
    ?>
    

    Edit: Corrected the code to show the form data and empty values errors seperatly.

    Explanation: The first if statement checks that the submitted form contained two fields, ign and email. This is done to stop the second if statement , in the case that ign or email weren't passed in at all, from throwing an error(message would be printed to server logs). The second if statement checks the values of ign and email to see if they contain data.

    0 讨论(0)
  • 2021-01-04 07:17

    isset() accepts more than just oneparameter, so just pass as many variables as you need to check:

    <?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!";   
        }
    ?>
    

    You could use empty() as well, but it doesn't accept more than a variable at a time.

    0 讨论(0)
  • 2021-01-04 07:20
    // if any of this session is set then
    if (isset($_SESSION['tusername']) || isset($_SESSION['student_login'])) {
      it will return true;
    } else {
      it will return false;
    }
    
    0 讨论(0)
  • 2021-01-04 07:23
     isset($_POST['ign'],$_POST['email']));
    

    and then check for the empty values.

    0 讨论(0)
  • 2021-01-04 07:26

    This is how I solved this issue:

    $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!";
    }
    
    0 讨论(0)
  • 2021-01-04 07:28

    Try this:

    <?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!";
        }
        ?>
    
    0 讨论(0)
提交回复
热议问题