3

Controller Code

app.post('/savedata', function(req, res) {
var cope = req.body;
console.log("On server side");
console.log(cope.Client_ID);
var queries = 
connection.query('update lv_billing.client SET Client_ID = ?, Client_Name = ?,Status = ?,Updt_Time = ?,Updt_By = ?,Updt_ID = ?,Cluster = ? where Client_ID = ?',cope.Client_ID,cope.Client_Name,cope.Status,cope.Updt_Time,cope.Updt_By,cope.Updt_ID,cope.Cluster,cope.Client_ID, function(err,res){
if(err) throw err;
    console.log('Inserted!');
})
});

The above code is throwing the error "this._callback.apply" is not even a function. To set a little context. i m trying to update my table with the new values from the array. 'cope' is an array which holds values which needs to be updated.

4 Answers 4

4

As @RugDealer mentioned, you should provide the callback function as the second or third argument. If you are using the mysql module you can alter your function like this:

    app.post('/savedata', function(req, res) {
      var cope = req.body;
      console.log("On server side");
      console.log(cope.Client_ID);
      var params = [cope.Client_ID, cope.Client_Name, cope.Status, cope.Updt_Time, cope.Updt_By, cope.Updt_ID, cope.Cluster, cope.Client_ID];
      var queries = 
      connection.query('update lv_billing.client SET Client_ID = ?,Client_Name = ?,Status = ?,Updt_Time = ?,Updt_By = ?,Updt_ID = ?,Cluster = ? where Client_ID = ?',params, function(err,res){
       if(err) throw err;
       console.log('Inserted!');
      });
    });

For more information checkout the source: https://www.npmjs.com/package/mysql

Sign up to request clarification or add additional context in comments.

Comments

2
var q = con.query('UPDATE table_Name SET wordstype_count = wordstype_count + ? Where user_id = ?', [data.keyCount , data.userId],function (err, result) {
                if (err) throw err;
              }
            );

use your parameter like this. this is working fine for me.

Comments

0

You're callback is supposed to be your second parameter.

connection.query('query string here', callback_function_here);

Just concatenate your variables like so, otherwise they are considered as parameters:

'update lv_billing.client SET Client_ID = ' + cope.Client_ID + ' ... '

Comments

0

I'm not sure which mysql driver you are using because you didn't say so or give any clues in the code you wrote. With that said, I assume that the code should look more like this:

app.post('/savedata', function(req, res) {
  var cope = req.body;
  console.log("On server side");
  console.log(cope.Client_ID);
  var queries = connection.query('update lv_billing.client SET Client_ID = ' + cope.Client_ID + ', Client_Name = ' + cope.Client_Name + ' ,Status = ' + cope.Status + ' ,Updt_Time = ' + cope.Updt_Time + ',Updt_By = ' + cope.Updt_By + ',Updt_ID = ' + cope.Updt_ID + ',Cluster = ' + cope.Cluster + ' where Client_ID = ' + cope.Client_ID, function(err,res){
  if(err) throw err;
    console.log('Inserted!');
  })
});

Usually when you get an error saying something is not a function, it means that you are trying to use something as a function that is not a function. My assumption is that you are using a library similar to this:

https://github.com/mysqljs/mysql#performing-queries

Notice that the format for querying is like this:

.query(sqlString, callback)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.