J
J
Jesus_newrba2018-12-02 07:57:40
Express.js
Jesus_newrba, 2018-12-02 07:57:40

How to make a query in mysql?

module.exports = {
  addAnnPage: (req, res) => {
        res.render('add-ann.ejs', {
            title: "Welcome | Add a new"
            ,message: ''
        });
    },
    addAnn: (req, res) => {

        let first_name = req.body.first_name;
        let last_name = req.body.last_name;
        let number = req.body.number;
        let auto = req.body.auto;
        let info = req.body.info;
        let price = req.body.price;
        let usernameQuery = "SELECT * FROM `ann` WHERE first_name = '" + first_name + "'";
        db.query("INSERT INTO `ann` (first_name, last_name, number, info, price, auto) VALUES ('"+first_name + "', '" + last_name + "', '" + number + "', '" + info + "', '" + price + "', '" + auto + "')", function(err, info) {
    console.log(info.insertId);
});
     }
 }

In the database, after sending the request, undefined appears in the fields

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Petrov, 2018-12-03
@chel1

Check what comes in req.body.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question