var express = require('express');
var router = express.Router();

router.get('/', function(req, res, next) {
    let query = "SELECT * FROM product WHERE description LIKE ? OR productname LIKE ?";
    db.all(query, [`%${req.query.searchcriteria}%`, `%${req.query.searchcriteria}%`], (err, result) => {
        if (err) {
            res.render('error', {error: err});
        } else {
            res.render('search', {allrecs: result});
        }
    });
});

module.exports = router;