0

I'm using npm package mysql and I want to do an update query that gets an object and knows what are the fields that need an update

function editPlaylistDB(publicID, name, description,callback) {

    let insertData={};
    if (name!==null){
        insertData.name=name;
    }
    if(description!==null){
        insertData.description=description;
    }

     db.query('update playlists set name=insertData.name,description=description  WHERE public_id= ?',[publicID]).then((rows=>{
        console.log(rows);
        callback(rows);

    })).catch((err)=>{
        console.log(err);
        callback(null);
    });
}

This is the error message

Error: ER_BAD_FIELD_ERROR: Unknown column 'insertData.name' in 'field list'

I don't know if it is even possible.

2 Answers 2

1

Why not add another parameterized variable like the public_id? Also, it looks like your description was not being set correctly either. Also, double check how you are setting insertData.description and where that should go.

db.query('update playlists set name=?,description=?  WHERE public_id= ?',[insertData.name, (description var goes here), publicID]).then((rows=>{
    console.log(rows);
    callback(rows);

})).catch((err)=>{
    console.log(err);
    callback(null);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Updated, looks like your description column was not being set correctly either.
0

Maybe you need to use parameterised string:

`update playlists set name=${insertData.name},description=${description}  WHERE public_id= ?`

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.