gpt4 book ai didi

jquery - 使用 mysql 和 nodejs 更新查询时出现 ER_PARSE_ERROR

转载 作者:行者123 更新时间:2023-11-29 18:35:35 24 4
gpt4 key购买 nike

我查看了与此类似的其他问题,但我似乎无法找到或解决我的问题。请帮忙。

我正在做的是将输入数据从客户端传递到服务器,以便它可以更新 ID 匹配的特定行。我尝试了不同的方法来获取传递给查询的 ID,但最终还是出现 ER_PARSE_ERROR。

路线

app.post('/configuration_materials/editsend/:id', isLoggedIn, materialpricingTable.UPDATEMaterial);

客户端/jQuery和ajax功能

$(function() {



$('body').on('click', '.SubmitEditMat', function() {

var materialIDedit = this.id.split('-')[1];


var clientMtrlApplication = $('#clientMtrlApplication');
var clientMtrlType = $('#clientMtrlType');
var clientMtrlSpec = $('#clientMtrlSpec');
var clientPricePerSheetORFt = $('#clientPricePerSheetORFt');
var clientSqFtofSheetORLen = $('#clientSqFtofSheetORLen');
var clientWtPerFt = $('#clientWtPerFt');
var clientWtPerItem = $('#clientWtPerItem');
var clientMtrlPricePerFt = $('#clientMtrlPricePerFt');
var clientMtrlPricePerLb = $('#clientMtrlPricePerLb');
var clientMtrlPricePerItem = $('#clientMtrlPricePerItem ');
var clientLaborHrsPerFt = $('#clientLaborHrsPerFt');
var clientLaborHrsPerItem = $('#clientLaborHrsPerItem');
var clientNotes = $('#clientNotes');

var divAddMatSuccess = $('#modifiedModalEditMat');


$.ajax({
url: '/configuration_materials/editsend/' + materialIDedit,
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({

serverMtrlApplication: clientMtrlApplication.val(),
serverMtrlType: clientMtrlType.val(),
serverMtrlSpec: clientPricePerSheetORFt.val(),
serverPricePerSheetORFt: clientPricePerSheetORFt.val(),
serverSqFtofSheetORLen: clientSqFtofSheetORLen.val(),
serverWtPerFt: clientWtPerFt.val(),
serverWtPerItem: clientWtPerItem.val(),
serverMtrlPricePerFt: clientMtrlPricePerFt.val(),
serverMtrlPricePerLb: clientMtrlPricePerLb.val(),
serverMtrlPricePerItem: clientMtrlPricePerItem.val(),
serverLaborHrsPerFt: clientLaborHrsPerFt.val(),
serverLaborHrsPerItem: clientLaborHrsPerItem.val(),
serverNotes: clientNotes.val()
}),

success: function(response) {
console.log(response);


divAddMatSuccess.html('');

divAddMatSuccess.append('\
<div class="alert alert-success">\
<strong>Success! Updated: </strong> ' + clientMtrlApplication.val() + clientMtrlType.val() + clientMtrlSpec.val() +'\
</div>\
');


}


});



});
});

服务器端,带有 UPDATEMaterial 和 MySQL 查询的materialpricingTable.js

//查询

exports.sqlEditMaterial = "UPDATE generictablenamepleaseignore SET ? where ID = ?;";

//UPDATE Material 函数

exports.UPDATEMaterial = function (req, res) {
var weErrored = false;

var idOfMaterial = req.params.id;


var post = {

// NAMEINDATABASE: NAMEONFORM
Application: req.body.serverMtrlApplication,
MaterialType: req.body.serverMtrlType,
MtrlSpecs: req.body.serverMtrlSpec,
PricePerSheetORFt: req.body.serverPricePerSheetORFt,
SqFtofSheetORLength: req.body.serverSqFtofSheetORLen,
WtPerFt: req.body.serverWtPerFt,
WtPerItem: req.body.serverWtPerItem,
MtrlPricePerFt: req.body.serverMtrlPricePerFt,
MtrlPricePerLb: req.body.serverMtrlPricePerLb,
MtrlPricePerItem: req.body.serverMtrlPricePerItem,
LaborHrsPerFt: req.body.serverLaborHrsPerFt,
LaborHrsPerItem: req.body.serverLaborHrsPerItem,
Notes: req.body.serverNotes
};

var sendData = post + idOfMaterial;

mySqlController.connection.query(exports.sqlEditMaterial, sendData ,
function (err) {
if (err) {
console.log(err.code);
weErrored = true; // setting the error to true, this is used to display a message on the front end

}

res.send('Success!');


});
}

最佳答案

您不能对对象使用 + 运算符(例如 post)。在这种特殊情况下,您需要传递一个包含两个值的数组:

var sendData = [post, idOfMaterial];

此外,SQL 查询末尾的分号是不必要的,只有在使用命令行 MySQL 客户端时才需要(或者当然是在单个查询中执行多个语句时)。

关于jquery - 使用 mysql 和 nodejs 更新查询时出现 ER_PARSE_ERROR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45335381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com