Sunday, 16 April 2017

Node js mysql returns empty result when asking with AND operator

I have trouble with MySQL querry in Node.js

This is my source code:

        var passwordHash = sha512(data.passwordLogin).toString('hex');

        database.query('SELECT `name`, `email`, `email-validated` FROM Players WHERE `email` = ? AND `password` = ?', [database.escape(data.name), database.escape(passwordHash)], function (error, results, fields) {
            if(error)
                logger.error(error); 
            else
            {
                logger.debug(results[0].name); //This line returns an empty array
            }
        });

It is working fine when i ask only for email, but with AND operator in query it returns an empty array as result.

Data given to query and data in database are equal.

Also trying to acces something like results[0], results[0][0] or results[0].name causes server(app.js) to crash.

Any ideas to solve this? If you need more information about the source code just ask.

I really appreciate your help.



via Dexit

No comments:

Post a Comment