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

172
Vistas
How to change a value in MySQL Database to a value of a variable defined in JS/Node?

In the database a customer has unique id which is defined below as idEmail = id, I am trying to find the customer in the database against this id and then replace their hashed password but I'm struggling with the SQL syntax as I'm not sure how I can give the "password" & "emailId" in the query a value rather than setting "password" to "password" where "id" = "emailId" and not the actual value of the emailId variable:

app.post("/reset_password/:id/:token", (req, res, next) => {
const { id, token} = req.params;
const idEmail = id;
const {password, password2} = req.body;
db.query("SELECT * FROM user WHERE id = ?", [idEmail], async (error, results) => {
if (id != results[0].id) {
  res.send("Invalid id" + id + results[0].id)
  return
}

const secret = JWT_SECRET + results[0].password
try {
  const payload = jwt.verify(token, secret)
  if (password === password2) {
    let hashedPassword = await bcrypt.hash(password, 8);
    
    db.query(
      "UPDATE user SET password = 'password' WHERE id = 'emailId' ",
      {
        password: hashedPassword,
        emailId: idEmail,
      },
      (error, results) => {
        if (error) {
          console.log(error);
        } else {
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Solved with:

db.query("UPDATE user SET password = ? WHERE id = ?", [hashedPassword, idEmail], 
(error, results)
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