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.
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.
Share Improve this question asked Jul 22, 2016 at 12:57 user2860954user2860954 1752 silver badges24 bronze badges4 Answers
Reset to default 4As @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./package/mysql
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.
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 + ' ... '
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./mysqljs/mysql#performing-queries
Notice that the format for querying is like this:
.query(sqlString, callback)