I have the following code:
connection.query("SELECT * FROM accounts_data WHERE new_username LIKE '%" + username + "%';", function (error, results, fields) {
});
and I am getting the following error
SELECT * FROM `accounts_data` WHERE `new_username` LIKE '%preloved_bys%'
^^^^^
SyntaxError: Unexpected identifier
at wrapSafe (internal/modules/cjs/loader.js:1054:16)
at Module._compile (internal/modules/cjs/loader.js:1102:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
what is wrong with the query? when i execute it via phpmyadmin it works just fine
i get success with do following :
var value = 'sc188203395acc255';
connection.query('SELECT * from emp where empid like ?', '%' + value + '%', ...)
Turn on debugging in the driver (pass debug:true as argument to mysql.createConnection ), it doesn't escape the percent sign
One More Way to Slove this Error :
"SELECT * FROM emp WHERE name empid " + connection.escape('%'+value+'%')
use connection.escape alternate way to do same things
One More Way to Solve this Error :
reinstall module on your project because sometimes error can be solved by reinstalling it
delete node_modules and package-lock.json and last run npm install
It seems there is nothing wrong with the following code.
but fyi, SyntaxError: Unexpected identifier occurs due to some reasons, mentioned below:
case-sensitive language when you pass any parameter into it like 'new_username'. Recheck it should be correct.' or "invalid identifier. let str = '%'+username+'%';
let sql = "SELECT * FROM accouts_data WHERE new_username LIKE ?";
connection.query(sql, str, function(err, result) {
if(err) throw err
});
npm install
It'll update every module with their latest version automatically.