2013-05-20 66 views
0

我想插入從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) ; 
    } 
}); 
+0

值,那麼整數應該被引用,也許這就是原因所在。你得到任何錯誤錯誤? –

+0

怎麼樣一個日誌,所以你知道你甚至到達這裏(假設你正在查看console.log(err) – Drew

+0

沒有它記錄「插入」,但在表中沒有插入任何東西 – ana

回答

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) ; 
    } 
}); 
+0

此代碼中存在語法錯誤 – ana

+0

現在嘗試......... – SanketS

+1

*請*不建立這樣的查詢字符串,使用佔位符或至少[提供的轉義字符串的方法](https://github.com/felixge/node-mysql#escaping-query-identif IERS)。 – robertklep