php - MySQL 表根本不使用 JSON 更新
问题描述
我正在做一个 CRUD 项目。我的所有其他功能都在工作,除了更新。我已经包含了一个 catch 来查看 SQL 语句中是否有任何错误并且它没有捕获任何内容。当我按下保存更改时,代码会被执行,但不会反映我的表中的任何更改。我也检查了所有的错误日志,没有什么明显的。有任何想法吗?(我不得不从字段中删除详细信息,因为它们包含可识别信息)。
function edit(rowID) {
$.ajax({
url: 'ajax.php',
method: 'POST',
dataType: 'json',
data: {
key: 'getRowData',
rowID: rowID
}, success: function (response) {
$("#editRowID").val(response.rowID);
$("#fullName").val(response.fullName);
$("#dob").val(response.dob);
$("#ethnicity").val(response.ethnicity);
$("#gender").val(response.gender);
$("#nhsNo").val(response.nhsNo);
$("#hospNo").val(response.hospNo);
$("#idMarks").val(response.idMarks);
$("#address").val(response.address);
$("#tableManager").modal('show');
$("#manageBtn").attr('value', 'Save Changes').attr('onclick', "manageData('updateRow')");
}
});
}
function manageData(key) {
var fullName = $("#fullName");
var dob = $("#dob");
var ethnicity = $("#ethnicity");
var gender = $("#gender");
var nhsNo = $("#nhsNo");
var hospNo = $("#hospNo");
var idMarks = $("#idMarks");
var address = $("#address");
var editRowID = $("#editRowID");
if (isNotEmpty(fullName) && isNotEmpty(dob) && isNotEmpty(ethnicity) && isNotEmpty(gender) && isNotEmpty(nhsNo) && isNotEmpty(hospNo) && isNotEmpty(idMarks) && isNotEmpty(address)){
$.ajax({
url: 'ajax.php',
method: 'POST',
dataType: 'text',
data: {
key: key,
fullName: fullName.val(),
dob: dob.val(),
ethnicity: ethnicity.val(),
gender: gender.val(),
nhsNo: nhsNo.val(),
hospNo: hospNo.val(),
idMarks: idMarks.val(),
address: address.val(),
rowID: editRowID.val()
}, success: function (response) {
alert(response);
}
});
}
}
$fullName = $conn->real_escape_string($_POST['fullName']);
$dob = $conn->real_escape_string($_POST['dob']);
$ethnicity = $conn->real_escape_string($_POST['ethnicity']);
$gender = $conn->real_escape_string($_POST['gender']);
$nhsNo = $conn->real_escape_string($_POST['nhsNo']);
$hospNo = $conn->real_escape_string($_POST['hospNo']);
$idMarks = $conn->real_escape_string($_POST['idMarks']);
$address = $conn->real_escape_string($_POST['address']);
$rowID = $conn->real_escape_string($_POST['rowID']);
if ($_POST['key'] == 'updateRow') {
$conn->query("UPDATE suspects SET fullName='$fullName', dob='$dob', ethnicity='$ethnicity', gender='$gender', nhsNo='$nhsNo', hospNo='$hospNo', idMarks='$idMarks', address='$address' WHERE id= '$rowID'");
exit('Record for '.$fullName.' updated.');
}
解决方案
推荐阅读
- java - Service Builder 没有添加一些依赖项?
- wordpress - Wordpress - 将 url 查询字符串转换为永久链接
- python - Boto3 - 等到 AWS 数据库迁移任务被删除
- oracle - Oracle 数据库 Sql 开发人员
- angular - “组件”类型上不存在属性
- ruby - 如何使用单个命令创建特定数量的数组?
- amazon-redshift - 添加时间戳在红移中不起作用
- c - 如何使用 c 获取连接在同一网络中的机器的名称和 IP 地址?
- node.js - aws xray 采样不适用于 http 状态代码
- javascript - 与直接调用函数相比,使用 call / apply 有什么好处?