Comparison operator != not working in field [closed]

The reason it does not work is due to a logic error, which becomes obvious if you follow the code manually for each value It has nothing to do with the select element, or special behaviour of ! or !=

So lets look at your conditional:

$_POST['gender'] != 'Male' || $_POST['gender'] != 'Female'
  • if ( gender is not male ) OR ( gender is not female )
    • then complain it must be male/female

So lets say that the gender is male:

  • if ( false ) OR ( true )
    • then complain it must be male/female

Since true is true, it resolves to if true and the complaint appears.

So it appears, the problem is a misunderstanding of how OR works

a OR b <- this resolve to true if either ‘a’, ‘b’, or both a and b are true.

What I think you meant was:

if ( gender is male OR gender is female ) is not true

rather than

if ( gender is not male ) OR ( gender is not female )

But finally, this question and answer has nothing to do with WordPress.