首页 > 解决方案 > 为什么我的代码仍在工作时会出现此错误?

问题描述

我收到此错误,但我不知道为什么会收到此错误,我的代码有效,但仍然有错误意味着某些事情不好。你能帮帮我吗?

在此处输入图像描述

这里:

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

数据库代码在这里。我希望它能帮助你帮助我解决这个问题:

function create(){

// query to insert record
$query = "INSERT INTO
            " . $this->table_name . "
  JSON.stringify({ "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;
}

标签: phpangularapi

解决方案


您需要将正文作为字符串传递。使用JSON.stringify({ "name": name, "location": location})而不是{ "name": name, "location": location}.


推荐阅读