0
 { Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''mom12345'' at line 1}

I am trying to write a log in query in mysql using node js but for some reason, I keep getting the above error. Kindly can anyone assist me.

var logininfo={
username:username,
password:password

};
con.query('SELECT id FROM userinfo WHERE username=? and password ?',logininfo, function (error, results, fields) {
            if (error) {
                console.log("error ocurred",error);

            } else {
                console.log('The solution is: ', results);
                if (results.length > 0) {
                    if ([0].password == password) {
                       console.log("Login Successful");

                    }
                    else {
                        console.log("Username and password donot match");
                    }
                }
            }
        })

    }
0

2 Answers 2

1

You forgot equal to sign

WHERE username=? and password = ?
                           ---^
Sign up to request clarification or add additional context in comments.

Comments

0

Your second parameter should be an array of parameters not an object.

So change:

    var logininfo={
    username:username,
    password:password
    };

To:

    var logininfo=[
    username,
    password
    ];

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.