I'm using a function to check if a user is already registered on a site.
However I can't figure out how to get the value of rows out of the function selectEmail()
I'm trying to store it within temp, but it seems to store it within its own local version of it, and I'm left with an empty variable once the query part ends.
function checkEmail(email, req, res){
var temp;
dbConnect(req,res);
var query = 'SELECT EMAIL FROM USERS WHERE EMAIL="'+email+'"';
connection.query(query, function selectEmail(err,rows,fields){
if (err) {
throw err;
}
temp=rows;
})
dbClose(req,res);
console.log(temp);
if (temp==""){
console.log('No matching email in database');
return 0;
}
else{
console.log('Duplicate Email detected in database');
return 1;
}
}
I've heard I'm supposed to use a callback, but I can't figure out how to get that working either.