0

I am following this Youtube video https://www.youtube.com/watch?v=YYEC7ydDj4k learning the basics of node js with MySQL and I have typed the coded exactly as the video but I am getting the following error screenshot

let sql = 'UPDATE employee SET name = '${newName}' WHERE id = ${req.params.id}' ^

SyntaxError: Unexpected identifier at Object.compileFunction (node:vm:352:18) at wrapSafe (node:internal/modules/cjs/loader:1026:15) at Module._compile (node:internal/modules/cjs/loader:1061:27) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10) at Module.load (node:internal/modules/cjs/loader:975:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) at node:internal/main/run_main_module:17:47

Node.js v17.5.0

//update employee
app.get('/updateemployee/:id', (req,res) => {
    let newName = 'Updated name'
    let sql = 'UPDATE employee SET name = '${newName}' WHERE id = ${req.params.id}'
    let query = db.query(sql,err => {
        if(err {
            throw err
        }
        res.send('Employee Updated')
    })
})

Any help would be highly appreciated! Thank you!

0

1 Answer 1

1

To use variable substitution inside strings you need to use the backtick character ` and not quotes.

let sql = `UPDATE employee SET name = '${newName}' WHERE id = ${req.params.id}` 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much !

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.