0

I am trying to access data from my MySQL database and compare that data to my form data to authenticate sign in process. But the problem I am facing is that my database query is returning undefined values in the db.query() function. I have attached the code of my index.js below:

app.post("/api/get/signin", (req,res)=>{
    
    const userid = req.body.userId;
    userIdG = userid;
    const password = req.body.password;
    const consumerKey = req.body.consumerKey;
    const sqlSelect =
    `SELECT userid FROM signup WHERE userid = ? AND password = ? AND consumerKey = ?`;
     db.query(sqlSelect,[userid , password , consumerKey], (err, result)=> {
        console.log(result.userid);
        console.log(err);
        //console.log(err);
        if(result.userid == userid && result.password == password && result.consumerKey == consumerKey)
        {
            //res.send(result);
            console.log("Successfully Login");
            auth = true;
        }
        else
        {
            console.log('Local');
            console.log(userid);
            console.log(password);
            console.log(consumerKey);
            console.log("UnSuccessfully Login");
            auth = false;
        }
         
    })
})

Undefined data returned from the database

1 Answer 1

2

result will be an array (because queries can have multiple results), so to access the userid (of the first result, provided that there is one!):

console.log(result[0].userid)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.