php - 为什么我的代码仍在工作时会出现此错误?
问题描述
我收到此错误,但我不知道为什么会收到此错误,我的代码有效,但仍然有错误意味着某些事情不好。你能帮帮我吗?
这里:
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;
}
解决方案
您需要将正文作为字符串传递。使用JSON.stringify({ "name": name, "location": location})
而不是{ "name": name, "location": location}
.
推荐阅读
- android - Facebook Android 登录 - 传递详细信息
- c# - Entity Framework Core:对组合表的请求(组合键)
- oracle - 在正常的 oracle 函数中:ORA-06531:引用未初始化的集合
- jmeter - 通过 Jmeter 每秒发送并发 http 请求
- wcf - Biztalk WCF 不会显示自定义行为
- angular-cli-v6 - --dev 选项在 Angular CLI 中不起作用
- php - Laravel 5.6 Storage::download file not found
- gcc - 使用带有 gcc 的 std::chrono 运算符 ""s
- vba - 保存名称为日期的 Excel
- drupal - 通过升级删除了添加到 Drupal 核心的自定义功能