vendredi 14 juin 2019

PHP if statement logic doesn't seem to be working when detecting if values are NULL

The premise of the if statement is to check a selection of fields from the database to check if they are empty(NULL). It is wise to mention at this point before getting to StackOverflow, I have tried with isset(), empty() and is_null() and still haven't managed to get this if statement to correctly identify fields that are empty. I'm not sure if I am missing something so simple here.

As explained before, I have tried isset(), empty() and is_null() and the if statement still seems to get stuck at the first iteration of the if statement thinking one or more of the fields are empty when in fact, they all contain a value.

Here is the if statement:

    if(($xQI['businessName'] == NULL) OR ($xQI['businessAddress1'] == NULL) OR ($xQI['businessCity'] == NULL) OR ($xQI['businessCounty'] == NULL) OR ($xQI['businessPostCode'] == NULL) OR ($xQI['businessTelephone'] == NULL) OR ($xQI['businessEmail'] == NULL) OR ($xQI['businessContactName'] == NULL)) {
      header('location:../quotes-electricity-view.php?id=' . $idmd5 . '&v=n&c=bi');
    } elseif(($xQI['electricity_mpanBottom'] == NULL) OR ($xQI['electricity_mpanTop'] == NULL)) {
      header('location:../quotes-electricity-view.php?id=' . $idmd5 . '&v=n&c=mpan');
    } elseif(($xQI['electricity_SiteName'] == NULL)) {
      header('location:../quotes-electricity-view.php?id=' . $idmd5 . '&v=n&c=sname');
    } elseif(($xQI['electricity_SiteUsage'] == NULL)) {
      header('location:../quotes-electricity-view.php?id=' . $idmd5 . '&v=n&c=eac');
    } else {

//code continues here to execute rest of page

Any and all help is appreciated at this point. The if statement only choses the top output as result, taking you to the page with &v=n&c=bi as the result, meaning it thinks one of the business detail entries is missing, when in fact in the test, every one of the fields has a value. many thanks in advance.

Aucun commentaire:

Enregistrer un commentaire