使用PHP和mySQL从数据库中获取一行,然后进行编辑

So I'm using php to add or get data from a database. The way I'm trying to do this is to check if there is something there with that title, if there is, edit it, if not, add a new entry. This is the code I'm using:

$SQL_CHECK = "SELECT * FROM `doc`.`appointment` WHERE `title` = '$form_title';";
$checkQ = $con->query($SQL_CHECK);
    if(mysqli_num_rows($checkQ)>=1) {

      while($t = mysqli_fetch_array($checkQ)){
      $editID = $t['id'];

        //edit the entry
        $query_edit = "UPDATE `doc`.`appointment` SET `title`='$form_title' WHERE `id`=$editID;";
        $edit_row = $con->query($query_edit);

      }
  }elseif(mysqli_num_rows($checkQ)==0){
    //add new entry
     $query1 = "INSERT INTO `doc`.`appointment` (`start`, `end`, `title`, `body`) VALUES ('$start_date', '$end_date', '$form_title', '$form_body');";
     $result1 = $con->query($query1);

    } 

The problem I have is that, when I run the code, if there already is something there, it runs both queries (it adds a new one and edits the one existing)