I am new to node.js and learning it for quite few days and now I’m stuck with this app.post which is not working for me. If possible please let me know how to do app.update so it might be a big help in my learning process.
Kindly waiting for reply.
const mysql = require('mysql');
const express = require('express');
var app = express();
const bodyparser = require('body-parser');
app.use(bodyparser.urlencoded({extended: false}));
app.use(bodyparser.json());
app.listen(8000);
var mysqlconnection = mysql.createConnection(
{
host: 'localhost',
user: 'Naveen',
password: '',
database: 'employeedb',
multipleStatements: true
}
);
mysqlconnection.connect((err)=>{
if(!err)
console.log("DB connection successfull");
else
console.log('DB connection failed n Error : '+ JSON.stringify(err, undefined, 2) );
});
app.post('/employee' ,function (req, res, next) {
Name = req.query.Name,
Empcode = req.query.Empcode,
Salary = req.query.Salary
let sql = "INSERT INTO employee (Name, Empcode, Salary) VALUES (? , ?, ?)";
mysqlconnection.query('sql, (Name, Empcode, Salary) ', (err, rows, fields) => {
if (!err)
res.send("Insert succeed");
else
console.log(err);
});
});
```
and then I get these error messages:
**PS C:xampphtdocsfirst app> node index.js DB connection successfull Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sql, (Name, Empcode, Salary)' at line 1
(C:xampphtdocsfirst appnode_modulesexpresslibrouterindex.js:275:10) { code: 'ER_PARSE_ERROR', errno: 1064, sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'sql, (Name, Empcode, Salary)' at line 1", sqlState: '42000', index: 0, sql: 'sql, (Name, Empcode, Salary) ' }**