Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda