I'm new in the use ExpressJs, I created my own project to train myself. I would like to do a search bar so perform a select query with MySQL.
Here's my code :
let query = req.params.q;
console.log(query);
//var sql = "SELECT * FROM Movies WHERE movie_title like '%" + query + "%' OR movie_originalTitle like '%"+ query+"%'";
var sql = "SELECT * FROM Movies WHERE movie_originalTitle like ? OR movie_title like ?";
var values = [
['%' + query + '%', '%' + query + '%']
];
console.log(values[0]);
connection.query(sql, [values], (err, result, fields) => {
console.log(sql);
if (err) {
throw err;
};
JSON.stringify(result);
res.send({ movies: result });
});
I would like to do it with '?' parameter. I succeed to do it with one '?' but everytime I try to add the second parameter I got a MySQL Error
ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1
I don't know why the second '?' parameter throws me an error ...
Do I miss something ? Can anyone help me ? :)