Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
Node.JS and MYSQL How do I store a column value into a variable

So I have been working on a registration/login system for a theoretical bank and I'm trying to create accounts for the user who is signing up and adding it under their user ID however I'm not sure how to take the query from the database and put it into a variable so I can do this.

This is more or less how I'm trying to do it. However I'm not sure how to put the information that I'm grabbing into the userID variable

db.query('Select userID FROM users WHERE userEmail = ?', email, (error, results) => {
        if (error) {
            console.log(error);
        }

        var userID = <userID from the database>

        if(userID !== undefined)
        {
            db.query('INSERT INTO accounts SET ?', {users_userID: userID, accountType: 'Checking', accountBalance: 100}, (error, results) =>{
                console.log('creating checking');
                if (error) {
                    console.log(error);
                }
            });

            db.query('INSERT INTO accounts SET ?', {users_userID: userID, accountType: 'Savings', accountBalance: 100}, (error, results) =>{
                console.log('creating savings');
                if (error) {
                    console.log(error);
                }
            });
        }
    });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The results variable should contain the data retrieved from the db query.

Example (if there is a field called 'userID'):

db.query(... (error, results) => {
    var userID = results[0].userID;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!