Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda