php - 尝试在 phpmyadmin 中动态传递记录 ID 时获取 http_response_code(404)。我正在尝试将 MySQL on-pre 与 Salesforce 集成
问题描述
我正在尝试更新与动态传递的 id 对应的特定记录或行。有一条属于该id的记录。当我给 URL 后跟“?id=3”时,我收到 404 错误,说不存在这样的记录。想知道我犯了什么错误。以下是我的代码。
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
include_once '../config/database.php';
include_once '../objects/constitute.php';
$database = new Database();
$db = $database->getConnection();
$constitute = new Constitute($db);
$data = json_decode(file_get_contents("php://input"));
$constitute->id = isset($_GET['id']) ? $_GET['id'] : die();
$constitute->name = $data->name;
$constitute->address = $data->address;
$constitute->constitution_type = $data->constitution_type;
$constitute->organisation_id = $data->organisation_id;
if($constitute->update()){
http_response_code(200);
echo json_encode(array("message" => "Constitute was updated."));
}
else{
http_response_code(503);
echo json_encode(array("message" => "Unable to update constitute."));
}
?>
以下是 update() 方法:
function update(){
$query = "UPDATE
" . $this->table_name . "
SET
name = :name,
address = :address,
constitution_type = :constitution_type,
organisation_id = :organisation_id
WHERE
id = ?";
$stmt = $this->conn->prepare($query);
$this->id=htmlspecialchars(strip_tags($this->id));
$this->name=htmlspecialchars(strip_tags($this->name));
$this->address=htmlspecialchars(strip_tags($this->address));
$this->constitution_type=htmlspecialchars(strip_tags($this->constitution_type));
$this->organisation_id=htmlspecialchars(strip_tags($this->organisation_id));
$stmt->bindParam(':id', $this->id);
$stmt->bindParam(':name', $this->name);
$stmt->bindParam(':address', $this->address);
$stmt->bindParam(':constitution_type', $this->constitution_type);
$stmt->bindParam(':organisation_id', $this->organisation_id);
if($stmt->execute()){
return true;
}
return false;
}
另外,当我尝试在邮递员中传递更新的记录时,我得到了成功代码。但是记录没有得到保存。请让我知道我在哪里做错了。
解决方案
推荐阅读
- email - 当地址为空时,电子邮件是否会引发异常
- gitlab-ci - 如何在 gitlab-ci docker 容器中使用 docker-py 获取 docker 客户端?
- jquery - 附加容器时按 id 隐藏每个元素
- asterisk - 为什么在 yocto 星号的最终图像中不可用?
- c# - Xamarin-Android 和 UWP 之间的蓝牙连接
- html - 网站顶部的黑条 - 仅在 Firefox 上
- css - 下拉内容纯 CSS
- gettext - 在 Poedit 的 PO 文件中,如何提供关键字列表,以便为每个关键字自动提取评论?
- c# - 如何使用 VSTS 构建过程自动增加 nuget 包版本?
- tfs - “单元测试适配器抛出异常:无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息”