title: Update value only if Null php/mysql
body: <p>Thanks for checking out my question. I am trying to only update a value in my database if that field is null (so existing users won't be overwritten if someone tries to signup for a spot that is all ready taken and an error message will be output). I have listed below 2 of the most recent scripts I have tried. The first script works for updating the database if the select statement is not there but will overwrite users if entered for the same day and time. Thanks everybody!</p>
  
  <pre><code>$sql = ("SELECT `player1` FROM `users` where id = '$id' and Times = '$time'"); 
  
  
  $result = $conn-&gt;query($sql);
  
  if ($result-&gt;fetch_assoc === NULL) {
  $update_player = ("UPDATE users SET player1 = '$name' where id = '$id' AND Times =   '$time'")
  
  if($update_player){
  echo "Date for $name inserted successfully!";
  }
  }
  
  else {
    echo 'That spot is all ready taken!';
  }
  
  //2nd script 
  
  $query=mysql_query("UPDATE users SET 
  player1 = isNULL (player1, $name) 
  where id = '$id' AND Times = '$time'" );
  
  if($query){
  
   echo "Data for $name inserted successfully!";
  }
  
  else {
   echo 'That spot is all ready taken!';
  }
  </code></pre>