Sign in to follow this  

Javascript Scope Problem

Recommended Posts

    function MysqlName(sqlid, cb)
        iHandle.mysql.handle.query("SELECT `Username` FROM `accounts` WHERE `UserID`= ?", [sqlid], function (err, rows, fields) {
            if (err) throw err;


    var qwf = null;
        MysqlName(19, function (name) {
            qwf = name; 
            console.log("returning name: " + name) // return Firstname_Lastname (its ture)

    console.log(qwf); // RESULT NULL 


I did a function to pull the user name from the database. I can't assign it to global value. A very interesting mistake. How can I solve this?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.