如何在不加入Node.js的情况下更新两个表?

时间:2020-08-06 03:05:07

标签: mysql node.js

如何通过单击退休按钮来更新两个MySQL表?我创建了一个表格,您可以在其中根据以下所示的代理序列号进行编辑。通过单击“退休”按钮,它应将AgentStatus更改为Retired,并将该代理下的策略更改为另一个代理。 MySQL查询正确还是我要进行两个查询?

这在我的html中用于在agentavia中显示代理 Table with button

这是agentavia表,用于将状态从有效更改为已退休 enter image description here

这是policy1表,其中,他们单击退休按钮时,policyAgent将更改为另一个代理名称。 enter image description here

在mysql中更改数据的代码

router.get("/retire/:id", function (req, res, next) {
  const AgentId = req.params.id;
  const sql = `SELECT * FROM agentavia WHERE id= ${AgentId}`;
  db.query(sql, function (err, data) {
    if (err) throw err;
    res.render("modifyagent", { title: "Agent List", editData: data[0] });
  });
});

router.post("retire/:id", function (req, res, next) {
   const sql = `UPDATE * from agentavia and policy1 WHERE id= ? and agentStatus = 'Retired' and 
   policyAgent = 'Vani'` ;
          db.query(sql, function (err, data) {
            if (err) throw err;})
            alert("New agent shall take over your policies");
  });
});

0 个答案:

没有答案
相关问题