Saturday 3 June 2017

Can't find data from database after set it?

I have a piece of code which adds data to the database, then a function which gets the added data ID from the database. Problem is that, I get an error it couldn't be found, but it is in the database. How could I solve the problem?

[2017-06-03 18:01:25.855] [DEBUG] [default] - TypeError: Cannot read property 'id' of undefined

Here is how the function looks like

function getLastUser(hash, socket, user){
    query('SELECT * FROM users WHERE hash='+pool.escape(hash)+'', function(err, row){
        if(err){
            logger.error('Failed getting user hash: ' + user.name);
            logger.debug(err);
            socket.emit('message', {
                type: 'error',
                error: "Failed getting user hash"
            });
            return;
        }
        return row[0].id;
    });
}

Here the calling

getLastUser(hash, user, socket);



via Jordn

No comments:

Post a Comment