首页 > 解决方案 > 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.');
        }

标签: phpmysqljsoncrud

解决方案


推荐阅读