I’m trying to insert data from postman, using the column I get from req.body
.
I don’t see what am doing wrong, but for some reason my code only works with conn.query
and not conn.execute
. Why is that?
exports.createTour = async (req, res) => {
const tourData = req.body;
const conn = await mysql.createPool(config);
console.log(tourData);
try {
await conn.execute('INSERT INTO tours SET ?', [tourData]);
res
.status(200)
.json({ status: 'success', message: 'tour has been created' });
} catch (err) {
console.log(err);
res
.status(500)
.json({ status: 'fail', message: 'Failed to create a tour' });
}
};
New contributor
Saif Yehya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.