ana ana - 5 months ago 15
Node.js Question

insert query in mysql is not working

I have created table employees and i want to insert data in this table i am writing a simple query

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


The output it display is not inserted

i have createde a employees table

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


Is there any problem in writing the query?

Answer

Your query syntax is wrong, you have two extra commas in the values section (around the empty string value). Try this instead:

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"
)
Comments