node js check if a user exists in mysql 1

node js check if a user exists in mysql

connectDB.query("SELECT ACCOUNT_ID FROM registration WHERE ACCOUNT_ID = '"+ userAccnt +"'", function(err, result, field){
     if(result.length === 0){
        //new user logic
}else{  
    //existing user, redirect to another page 
 }
        }

Here is what the above code is Doing:
1. It’s checking if the user account exists in the database.
2. If it does, it redirects to another page.
3. If it doesn’t, it does nothing.

I want to change the logic so that if the user account doesn’t exist, it redirects to another page.

I tried this:

Similar Posts