php - !is_null() not working as expected -


"itemprop =" text ">

dispatch_address_postcode

is not compulsory and even if it still runs Is empty:

  if & amp; amp; is_null ($ _ post ['personal_info_surname']) in & amp; amp; (if_null ($ _ post ['personal_info_first_name']) ; Is_null ($ _post !! ['personal_info_email']) & amp; amp; amp ;! is_null ($ _ post ['personal_info_telephone']) & amp; amp;; is_null ($ _post ['dispatch_address_country' ]) & Amp; amp;! Is_null ($ _ post ['dispatch_address_first_name']) & amp; amp; is_null ($ _ post ['dispatch_address_surname']) & amp; amp; amp;; is_null ($ _ Post ['dispatch_address_address']) & amp; amp ;! is_null ($ _posts) In & amp; amp; amp; is_null ($ _ post ['dispatch_address_county']) & amp; amp; amp; amp;! Is_null ($ _ post ['dispatch_address_postcode']) & amp; amp; ; (($ _POST ['PAYMENT_METHOD'] == "Payment by credit card.") |! | ($ _POST ['Payment_math'] == "Make a new payment by credit card.") & Amp; Is_null ($ _ POST ['card_number']) &! Is_null ($ _ POST [ 'Expiration_date']) & amp; what is?   

"text" >

" dispatch_address_postcode is not mandatory and it will still work if it is empty ..."

Just look at that sentence again If the area is not compulsory, then it is absolutely fine if the code is run if the field is empty If no area is mandatory Do not compulsorily check with.

However the real problem is that, is_null is only the variable null . > Null , if they are empty, they will be '' (an empty string). All your ! Is_null test always will be correct , and if you do not have a variable set you will get a warning (which is not something that you want to do). The more appropriate examination will be.

More tests will include an exam if the price is valid (Email looks like an email address, does the telephone have at least X marks?). There is no joy to see the if situations.

  $ mandatory field = array ('foo' = & gt; 'email', 'bar' = 'gt;' telephone '); Foreign currency ($ compulsory $ field as field = & gt; $ rule) {If (empty ($ _ POST [$ field]) ||! Valid barrel ($ _ POST [$ field], $ rules) { RaiseHell (); }}  

Comments