0
votes

I try to insert some data into mysql data base using post method, but it ain't ,keep showing mysql synta error

   app.post('/form',function (req,res) {
        var post = req.body

  dbconn.query('INSERT INTO employee SET?',[post],function(err,result){
                  if(err)

               console.log(err);
           else
               console.log('inserted ');

        });

the error : code: 'ER_PARSE_ERROR', errno: 1064, sqlMessage: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'\' at line 1', sqlState: '42000', index: 0, sql: 'INSERT INTO employee SET ' }

1
i have 4 columns like employee(EmpID,Name,EmpCode,Salary) - itjuba

1 Answers

1
votes

Insert query is not correct syntax.

and please make sure post variable is contain right array

It should be

post = [
    [EmpID1, Name1, EmpCode1, Salary1],
    [EmpID2, Name2, EmpCode2, Salary2]

];

Below, I have updated code base.

 dbconn.query('INSERT INTO employee (EmpID, Name, EmpCode, Salary) VALUES 
   ?',[post],function(err,result){
        if(err)
           console.log(err);
        else
           console.log('inserted ');

 });