figuringout Posted February 20, 2008 Share Posted February 20, 2008 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. Quote Link to comment Share on other sites More sharing options...
Chris92 Posted February 20, 2008 Share Posted February 20, 2008 use the empty() function to check if its NULL or false: if ( empty($supplierEmail2) ) { echo "No email"; } else { echo $supplierEmail2 . "<br />"; } Quote Link to comment Share on other sites More sharing options...
revraz Posted February 20, 2008 Share Posted February 20, 2008 Try comparing it to strlen 0 instead. I dont think NULL is a string. Quote Link to comment Share on other sites More sharing options...
schilly Posted February 20, 2008 Share Posted February 20, 2008 its NULL not "NULL" or do strcmp($string,"") == 0 Quote Link to comment Share on other sites More sharing options...
figuringout Posted February 21, 2008 Author Share Posted February 21, 2008 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? Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 21, 2008 Share Posted February 21, 2008 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, Quote Link to comment Share on other sites More sharing options...
figuringout Posted February 21, 2008 Author Share Posted February 21, 2008 Thanks Uniflare your snippet will be very useful. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.