0
我已經看過類似的其他問題,但我似乎無法找到我的問題或解決它。請幫忙。ER_PARSE_ERROR更新與MySQL和nodejs查詢
我在做什麼是將輸入數據從客戶端傳遞到服務器,以便它可以更新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>\
');
}
});
});
});
服務器端,materialpricingTable.js與UPDATEMaterial和MySQL查詢
//查詢
exports.sqlEditMaterial = "UPDATE generictablenamepleaseignore SET ? where ID = ?;";
// UPDATEMaterial功能
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!');
});
}
啊。好的!這工作。非常感謝你提供的信息。 – Slait