0

I have an app in which i take input from user via post and then insert those inputs in db. Insertion of integer is resulting in error. invalid input syntax for integer.Please help. Any help would be appreciated.

ws.post('/nextq',function(req,res){

var user_name = req.body.InputName;
var user_add  =  req.body.InputAddress;
var user_mno=req.body.InputMno;
var user_age=req.body.InputAge;
var user_email=req.body.InputEmail;
var user_job=req.body.InputJob;
console.log(user_name + user_add + user_mno + user_age + user_email +  user_job);
if(!(user_name = null) || !(user_add = null) || !(user_mno = null)|| !(user_age = null)|| !(user_email = null)|| !(user_job = null))
{
client.connect(function(err){
if(err){
    return console.error('Could not connect to postgres' , err);
}
client.query("INSERT INTO \"Users\" (\"name\",\"address\",\"mno\",\"email\",\"age\",\"job\") VALUES ('user_name','user_add','user_mno','user_email','user_age','user_job')",function(err,result){if(err) {
  return console.error('error running query', err);
}

1 Answer 1

0

Try this

client.query("INSERT INTO Users (name, address, mno, email, age, job) VALUES ($1, $2, $3, $4, $5, $6)", [user_name, user_add, user_mno, user_email, user_age, user_job], function(err,result){if(err) {
  return console.error('error running query', err);
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.