有关mysql和nodejs的更新查询的ER_PARSE_ERROR

时间:2017-07-26 19:02:06

标签: jquery mysql node.js

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

我正在做的是将输入数据从客户端传递到服务器,以便它可以更新ID匹配的特定行。我尝试了将ID传递给查询的不同方法,但我仍然以ER_PARSE_ERROR结束。

路线

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

Client / 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 = ?;";

// 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!');


        });
}

1 个答案:

答案 0 :(得分:0)

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

var sendData = [post, idOfMaterial];

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