在mysql中插入查询不起作用

时间:2013-05-08 10:15:04

标签: mysql node.js

我创建了表员工,我想在此表中插入数据,我正在编写一个简单的查询

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))'
);

编写查询时有问题吗?

1 个答案:

答案 0 :(得分: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"
)