Socket.io, Node.js: How can a javascript variable be passed to mysql query from in a javascript.js?
There is an error when a variable of value '222.222.222.222', is attempted to be passed into the mysql query, but not when a variable having a value of '2' is passed into the same mysql query.
Any help would be greatly appreciated.
This gives error:
var javascriptVariable = '222.222.222.222';
$query = 'INSERT INTO misc_table (misc_field) VALUES ('+javascriptVariable+')';
connection.query($query, function(err, rows, fields) {
if(err){
console.log("An error ocurred performing the query.");
return;
}
console.log("Query succesfully executed: ", rows);
});
This does not give error:
var javascriptVariable = '2';
$query = 'INSERT INTO misc_table (misc_field) VALUES ('+javascriptVariable+')';
connection.query($query, function(err, rows, fields) {
if(err){
console.log("An error ocurred performing the query.");
return;
}
console.log("Query succesfully executed: ", rows);
});
misc_table(misc_field) VALUES ('+javascriptVariable+')'; :)An error ocurred performing the query.