Reputation: 3083
Hi
I have this query on node.js. This is my server side file:
function doquery(select,from,where,value) {
var con = mysql.createConnection({
host: "localhost",
database: "db545",
user: "root",
password: "mypass"
});
return con.query("SELECT " + select + " FROM " + from + " WHERE " + where + value);
};
io.on('connection', (socket) => {
// when the client emits 'add user', this listens and executes
socket.on('add user', (username) => {
dispname = doquery('name','members','member_id','1');
but the variable dispname is resulting in [object object] but since this is server side Im not getting any errors so I cant debug it. What is wrong?
Thank you.
Upvotes: 0
Views: 903
Reputation: 310993
[object Object]
is the default string representation of an object. If you want to properly debug the result, you could serialize it to JSON:
console.log(JSON.stringify(dispname));
Side note:
By concatenating strings to your SQL query like that you're making the application vulnerable to SQL Injection attacks. I strongly recommend you look into prepared statements instead.
Upvotes: 2