Jump to content

Simple IF statement not working


figuringout

Recommended Posts

I'm struggling to understand why this doesnt work. I have an array which I breakdown annd assign the various parts off to variables, then want to test if one is NULL if it is ignore it.

 

$supplierEmail = $supplierarray[0];
$supplierId = $supplierarray[1];
$supplierEmail2 = $supplierarray[2];

 

in some cases $supplierEmail2 is null so I want to ignore it, so I thought I could do this.

 

if ($supplierEmail2 == "NULL")
echo "No email";
else
echo $supplierEmail2 . "<br />";

 

this doesnt work and I cant figure out why. I even set the field to be something other than null and test it but still I dont get the results I thought I would get.

Link to comment
https://forums.phpfreaks.com/topic/92130-simple-if-statement-not-working/
Share on other sites

I've tried everything you all suggested but still it does not work. What else could it be?

 

The data is coming from a form.

$supplier = $_POST[suppliers_info];
$supplierarray = explode(",",$supplier);
$supplierEmail = $supplierarray[0];
$supplierId = $supplierarray[1];
$supplierEmail2 = $supplierarray[2];

 

then I test the variable $supplierEmail2 to see if is empty but it always returns true. I've even set the field in the database to be 'none' and tried to test for this, but still it doesnt work.

Is it something to do with the variable coming from an array?

 

 

 

if your testing if an email has been sent do this:

 

if(!preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i", $supplierEmail2) ) {

      echo("Email Address incorrect format");

}

 

hope this helps,

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.