2013-05-08 114 views
-1

我已經創建表的員工,我想在這個表中插入數據我寫一個簡單的查詢插入查詢不工作

client.query('INSERT INTO employees (id,firstName, lastName, fullName, managerId, managerName, title, department, cellPhone, officePhone, email, city, pic, twitterId, blog) VALUES (1,"amina", "yousuf", "aminayousuf",1,,"",,"ceo","df","4334","455","dfsfsdf","dsfsf","fdfdsf", "fsdf" ,"sdf")', function(err,data){ 
    if(err){ 
     console.log(" not inserted") ; 

    } 
    else{ 
     console.log("insert"); 
    } 
    client.end(); 

輸出它顯示未插入

我有創建員工表

client.query('CREATE TABLE employees ' + 
'(id INT(11),' + 
' firstName VARCHAR(255), ' + 
' lastName VARCHAR(255), '+ 
' fullName VARCHAR(255),' + 
'managerId INT(11),'+ 
'managerName VARCHAR(255),'+ 
'title VARCHAR(255),'+ 
'department VARCHAR(255),'+ 
'cellPhone VARCHAR(255),' + 
'officePhone VARCHAR(255),' + 
'email VARCHAR(255),' + 
'city VARCHAR(255),'+ 
'pic BLOB ,' + 
'twitterId VARCHAR(255),' + 
'blog VARCHAR(255))' 
); 

在編寫查詢時是否有任何問題?

+2

什麼是'錯誤'?在詢問其他人之前,總是檢查返回的錯誤。 – 2013-05-08 10:15:59

+0

你的查詢是錯誤的。你用'1 ,,「」,,'。那是不對的。 – 2016-06-20 13:07:22

回答

1

你的查詢語法是錯誤的,你必須在values部分(圍繞空字符串值)兩個額外的逗號。試試這個:

INSERT INTO employees (
    id, firstName, lastName, fullName, managerId, managerName, title, 
    department, cellPhone, officePhone, email, city, pic, twitterId, blog 
) 
VALUES (
    1,"amina", "yousuf", "aminayousuf",1,"","ceo", 
    "df","4334","455","dfsfsdf","dsfsf","fdfdsf", "fsdf" ,"sdf" 
)