为什么我的“添加”按钮还添加了一个空对象

So my add button works but from time to time it adds also an empty object, not all the time though. So here is my code in the API:

function create(){

    // query to insert record
    $query = "INSERT INTO
                " . $this->table_name . "
            SET
                name=:name,location=:location";

                echo $query;

    // prepare query
    $stmt = $this->conn->prepare($query);
    if (!$stmt)
      var_dump($this->conn->errorInfo());

    // sanitize
    $this->name=htmlspecialchars(strip_tags($this->name));
    $this->location=htmlspecialchars(strip_tags($this->location));



    // bind values
    $stmt->bindParam(":name", $this->name);
    $stmt->bindParam(":location", $this->location);



    // execute query
    if($stmt->execute()){
        return true;
    }
var_dump($this->conn->errorInfo());
    return false;

}

And here is the one in the departmentService:

  addDepartment (name:string, location:string):Observable<any> {
      return this.http.post(this.depCreate,{
            "name": name,
            "location": location},
            httpOptions);
    }

u didnt added any check for empty values

if(!empty($this->name) && !empty($this->name))
{
// your code
}

Change this

 return this.http.post(this.depCreate,{
        "name": name,
        "location": location},
        httpOptions);
}

to

 return this.http.post(this.depCreate,{
        name,
        location},
        httpOptions);
}