分享
三行代码  ›  专栏  ›  技术社区  ›  Mkh_RMD

TypeError:参数回调在带有SQL查询的节点js中提供时必须是函数

  •  1
  • Mkh_RMD  · 技术社区  · 3 天前

    代码如下:

     application.post('/Modification/SaveEdit/:idd',function(req,res){
     var mem = req.body.memo;
    
     connection.query('UPDATE memos SET textMemo = ?',mem,'WHERE idMemo = ?',req.params.idd, function (error, results, fields){
            if (error) {
        console.log("error ocurred",error);
        res.send({
          "code":400,
          "failed":"erreur survenue"
        })
      }else{
        console.log('Resultats: ', results);
        res.send({
          "code":200,
          "success":"votre memo est bien modifié ! "
            });
      }
      });
    
    
    
    });
    

    我认为这是我查询的语法,但我不知道如何正确地编写它。

    错误如下:

    TypeError: argument callback must be a function when provided
    at Function.createQuery (/home/mohand/node_modules/mysql/lib/Connection.js:57:13)
    at Connection.query (/home/mohand/node_modules/mysql/lib/Connection.js:181:26)
    at /home/mohand/TpsWEB/DMajour/expreServer.js:146:13
    at Layer.handle [as handle_request] (/home/mohand/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/mohand/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/home/mohand/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/mohand/node_modules/express/lib/router/layer.js:95:5)
    at /home/mohand/node_modules/express/lib/router/index.js:281:22
    at param (/home/mohand/node_modules/express/lib/router/index.js:354:14)
    at param (/home/mohand/node_modules/express/lib/router/index.js:365:14)
    

    提前谢谢!

    1 回复  |  直到 3 天前
        1
  •  0
  •   abondoa    3 天前

    我想你可能在用 connection.query 不正确。也许查一下医生( https://github.com/mysqljs/mysql#performing-queries

    application.post('/Modification/SaveEdit/:idd',function(req,res){
     var mem = req.body.memo;
    
     connection.query('UPDATE memos SET textMemo = ? WHERE idMemo = ?',[mem,req.params.idd], function (error, results, fields){
            if (error) {
        console.log("error ocurred",error);
        res.send({
          "code":400,
          "failed":"erreur survenue"
        })
      }else{
        console.log('Resultats: ', results);
        res.send({
          "code":200,
          "success":"votre memo est bien modifié ! "
            });
      }
      });
    
    
    
    });