0

In my node JS I want to send a query to database to delete a record with under two conditions. One is id of the user and the second one is the name. However When I try to do this I receive an error:

 throw err; // Rethrow non-MySQL errors
    ^
 TypeError: this._callback.apply is not a function

And here is my code:

app.post('/delete',function(req,res){

received = req.body;
toDelete = {
    name: received.name,
    id: received.id
}

connection.query("DELETE FROM myTable WHERE User_ID = ? AND NAME = ?", toDelete.id, 
toDelete.name, function(err,results){
    if(err){return console.log(err)}
})

});

I think that number of passing arguments could be a problem. But how can I fix that when I want to use two parameters to find a record to delete?

3
  • Are you sure that's the right syntax of connection.query? What module are you using? Commented Jun 12, 2017 at 0:52
  • I use most common node js mysql connection -> github.com/mysqljs/mysql Commented Jun 12, 2017 at 0:54
  • Thanks! Now it was easy to check the syntax of the command :) Commented Jun 12, 2017 at 1:00

1 Answer 1

2

The syntax that you are using is wrong. It should be:

...[toDelete.id, toDelete.name]...

The values should be passed as array not as arguments.

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

2 Comments

Awesome! :)) Can you mark the answer as the correct one. It's a practice here in stackoverflow. Thank you!
No problem. Done! :)

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.