插入查询不会在表中插入值

时间:2013-05-20 12:00:25

标签: mysql node.js

我想插入从req.body获得的值。我将它保存在变量中,然后将它们作为插入查询中的值传递。但表中没有任何内容。 请帮帮我:

 var name=req.body.Name;
var CreatedBy=req.body.CreatedBy;
var CreatedDate=req.body.CreatedDate;
var ModifiedBy=req.body.ModifiedBy;
var ModifiedDate=req.body.ModifiedDate;
var email=req.body.Email;
var idAgency= Guid();
console.log(name);

client.query('INSERT INTO Agency (idAgency ,Name,CreatedBy, CreatedDate, ModifiedBy , ModifiedDate ,Email, Active ) VALUES (idAgency ,name ,CreatedBy ,CreatedDate, ModifiedBy ,ModifiedDate,email, 1)', function(err,data){
    if(err){
        console.log(err);
        console.log(" not inserted") ;
    }
    else{
        console.log("insert");
        console.log(data) ;
    }
});

1 个答案:

答案 0 :(得分:0)

尝试更改插入查询,如下所示:

var name=req.body.Name;
var CreatedBy=req.body.CreatedBy;
var CreatedDate=req.body.CreatedDate;
var ModifiedBy=req.body.ModifiedBy;
var ModifiedDate=req.body.ModifiedDate;
var email=req.body.Email;
var idAgency= Guid();
console.log(name);

client.query('INSERT INTO Agency (idAgency ,Name,CreatedBy, CreatedDate, ModifiedBy , ModifiedDate ,Email, Active ) VALUES (''' + idAgency + ''' ,''' +name + ''' ,''' +CreatedBy + ''' ,''' +CreatedDate + ''' , ''' +ModifiedBy + ''' ,''' +ModifiedDate + ''',''' +email + ''', '1')', function(err,data){
    if(err){
        console.log(err);
        console.log(" not inserted") ;
    }
    else{
        console.log("insert");
        console.log(data) ;
    }
});