con.connect(function(err){
if(err) throw err;
console.log("Connected!");
var sql = "USE test; INSERT INTO emails (FirstName, Email) VALUES ('Gaz', 'gmail');";
con.query(sql, function(err, result){
if(err) throw err;
console.log("Row inserted at position");
})
});
I'm trying to use node.js to insert a new row in an already existing table in MySQL. I connect properly but then an error is thrown in the console log which says the SQL syntax is wrong but I have checked and the sytax set for the sql variable works fine in SQL. The .query(sql, function()) format seems to be correct according to w3schools and other sources. I can't tell what the problem is.