title: Understanding XOR PHP
body: <p>I am writing section in my program to update a user, and there is password and confirm passwords.  I dont want to do anything to the password field in the DB unless they have filled the fields in.</p>
  
  <p>So I have error checking for:</p>
  
  <pre><code>if(($sql['password']!="") &amp;&amp; ($sql['cpassword']!=""))
              {
                  if($sql['password'] == $sql['cpassword'])
                  {
  //update
  }
  </code></pre>
  
  <p>}</p>
  
  <p>However I want to write a quick line to throw an error message if they only filled out one of the password fields.  So I figured:</p>
  
  <pre><code>if($sql['password'] ^ $sql['cpassword']) 
              {
                  echo You must fill out &lt;i&gt;both&lt;/i&gt; password fields and they &lt;i&gt;must&lt;/i&gt; match.";
              }
  </code></pre>
  
  <p>Would do it, but It doesnt seem to.  Then I added a NOT operator, !, and that seemed to work well, however if both fields have <em>nothing</em> in them, I still get the error message :(</p>
  
  <p>From the logic I can see from <a href="https://stackoverflow.com/a/4749620/1445985">this</a> answer, It would seem that simple XOR would work.  But
  But it doesnt, Can someone explain to me why?</p>