I've been learning about using sqlite3 as a dbms while developing through nodejs, specifically with express but I've been having problems as my code isn't running linearly?
var emailD = null;
var passwD = null;
db.each("SELECT Email emailS, Password pword FROM Users WHERE Email = ?", [email], (err, row) => {
emailD = row.emailS;
passwD = row.pword;
});
if(emailD == email){
if(passwD == password){console.log("Correct")}
else{console.log("Wrong PW")}
} else {console.log("Email not found")}
Essentially my if statements run before my search happens. I am doing it like this as I couldn't find a way within the search to return something if an email wasn't found and wanted to flag when such a thing happened.
db.each()returns a promise (or is at least an async call) which needs to be resolved before you can run your if. Perhaps for the case of your code, but you if statement under where you are setting theemailDandpasswDvariables.console.logthe two values within the callback, do you see that in the wrong order? What you're saying shouldn't be possible, which of course does not mean it didn't happen....