I am fairly new to Node.js and I want to execute multiple searches. I try to use req.params to get the search values from the textbox, but my code is not working. I tried to console the req.params.city , but nothing is displayed. I am using MySQL database.
Please see my code below:
Index.js
router.get('/searche/:city/:date',function(req,res){
let q = [req.params.city];
console.log(q)
db.query('SELECT city_name, state_name, party_name, price, image,
address, full_name FROM register natural join party where userid = id and city_name LIKE "%'+req.params.city+'%" ' ,function(err, rows, fields) {
if (err) throw err;
res.render('test', {party: rows});
});
});
form.ejs
<form action="/searche" autocomplete="off">
<input id="city" type="text" name="city" placeholder='Try "Minneapolis"'>
<input placeholder="Choose Date" class="textbox-n" name = "date" type="text" onfocus="(this.type='date')" onblur="(this.type='text')" id="date">
<button type="submit" class="searchButton"> <i class="fa fa search"></i></button>
</form>