Click here to Skip to main content
15,881,044 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello! hope you are doing well.
Im trying to update a database from nodejs.
But when i try to check it out on postman i got the error from the catch that i created.
Is it something that im doing wrong?.
The erro in the console is
Named parameter ":id" has no value in the given object.


What I have tried:

//PUT
server.put("/estudiantes/:id", async(req, res) => {
  const bodyParam = req.body;
  const idParam = req.params.id;
  try{
    const estudiantes = await db.query(`
    UPDATE estudiantes
SET :nombre :apellido :pais :edad
WHERE :id`,{
      replacements:{id: idParam.id,nombre:bodyParam.nombre,apellido:bodyParam.apellido,
        pais:bodyParam.pais,edad:bodyParam.edad},
          type: db.QueryTypes.UPDATE
        });
    res.status(200);
    res.json(bodyParam) 
  }catch (error){
    res.status(500);
    res.json({error:'Internal server error'})
    console.log(error.message);
  }

});
Posted
Comments
Afzaal Ahmad Zeeshan 19-Mar-21 11:15am    
Not sure, but I think this part replacements:{id: idParam.id needs to be only replacements:{id: idParam. Because you are reading the ID from the URL, and I would expect it to be a value, not an object.
Federico Arnaudo 19-Mar-21 17:38pm    
Thanks, but i tried and im still having the same error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900