This question already has an answer here:
I am working on below functions. I want to return value from function checkLogin to checkHubReg. I am not getting the return value from checkLogin function.
Could you please help me how to return the value from checkLogin function.
In checkLogin function i am retriving values from database. If the query returns empty means the user is logging for the first time, so i am inserting into table. otherwise old user.
exports.checkHubReg = function(msg1,msg2) {
var res = checkLogin(msg1,msg2);
console.log(res); // I am getting "Undefined here"
}
var result;
function checkLogin(msg1,msg2){
connection.query("SELECT lastlogin FROM users where username='"+msg1+"'", function(err, rows, fields){
console.log(rows);
if(!err){
if(rows.length == ' '){
result= "First time User";
connection.query('insert into users(username,password,lastlogin) values ("' + msg1 + '","' + msg2 + '",now())',
function(err, rows, fields){
if (err) throw err;
});
}else{
result = "Old User";
}
}
});
return result;
}
via Harish_S
No comments:
Post a Comment