json - MYSQL UPDATE TEXT field not working -
i'm trying update text field in mysql table. can't update query work, though original insert attempt works fine when user doesn't exist.
the purpose of function insert new row if user doesn't exist yet, , update textcolumn (that contains json) if user exists in table.
my code:
let first = 'jake'; let last = 'mcdonald'; let first_json = json.stringify({a:7, b:7}); let second_json = json.stringify({a:'updated'}); const row = { name: first, last_name: last, textcolumn: first_json, } db.query(`select * tablename name="${first}" , last_name="${last}"`, (err, result) => { if (err) console.log(err); if (result.length < 1) { db.query(`insert tablename set ?`, row, (err, result) => { console.log('new row created: ', result); }) } else if (result.length > 0) { console.log('row exists'); db.query(`update tablename set textcolumn=${second_json} name="${first}" , last_name="${last}"`, (err, result) => { console.log('updated: ', result); } ) } } ) the else if section giving me issues: reach inside console.log('row exists') update query logs "undefined".
the same update query works if try update tablename set name="somenewname" last_name="original_last_name", nothing happens when try update textcolumn.
Comments
Post a Comment