Reputation: 11
I try to get values that contains words in my sql database. I try with "contains" but I get an error. I work with SQL
This is my code:
router.post('/busca',isLoggedIn, async (req,res) => {
const {busca} = req.body;
const buscar = Object.values({busca});
const bus = await pool.query('SELECT * FROM links WHERE title CONTAINS ?',[buscar]);
res.render('links/busca',{buscar, bus});
});
I have this error:
UnhandledPromiseRejectionWarning: 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 '(title, 'a')' at line 1
Upvotes: 0
Views: 45
Reputation: 49375
Contains doesn't exist in mysql . use LIKE
const bus = await pool.query('SELECT * FROM links WHERE title LIKE ?',[%buscar%]);
Upvotes: 1
Reputation: 90
You can use LIKE operator :
SELECT * FROM links WHERE title LIKE '%word%';
if you are more than one word use and
or or
operator
SELECT * FROM links WHERE title LIKE '%word%' AND title LIKE '%secondword%';
Upvotes: 1