title: How do I NOT update a password field when it's left blank in $_POST?
body: <p><strong>UPDATE: I solved the problem myself and the answer is below. Carry on...</strong></p>
  
  <p>I have a form for updating your account using PHP and mySQL. On submit, it assigns all of the $_POST variables to the new user() object, and then does an update() method on the user object which runs an UPDATE query in SQL.</p>
  
  <p>The form obviously defaults to all of the user's information, EXCEPT for the password, which I don't prefill. It's blank unless they want to change their password.</p>
  
  <p>If I didn't do anything to address this, every account update would reset the person's password to "", since the field is blank on submit. That would be bad. So to fix it, I added this code:</p>
  
  <pre><code>    if(empty($_POST['password']) || is_null($_POST['password']) || !isset($_POST['password']) || $_POST['password'] == "") {
          $user-&gt;hashed_password = $edituser-&gt;hashed_password;
      } else {
          $password = $database-&gt;escape_value($_POST['password']);
          $user-&gt;hashed_password = md5($password);
      }   
  </code></pre>
  
  <p>Basically, if the $_POST password value is blank, set the password to the current user's password ($edituser is an object created in advance to save the current user's info if needed). Believe me, I tried it first with just if(empty()) because empty should work, but it didn't, so I added the null, the isset, and even the !== "" just to be safe.</p>
  
  <p>No matter what I do, the password is reset to blank. Why?</p>