Faisal Mashuri
Faisal Mashuri

Reputation: 3

req.params.id is undefined, ReferencesError : id is not defined

here is the url in browser

http://localhost:8888/update/1

this is the code for the route

router.addRoute("/update/:id", (req, res) => {
  conn.query(
    "select * from mahasiswa where ? ",
    { no_induk: req.params.id },
    function (err, rows, field) {
      if (rows.length) {
        if (req.method.toUpperCase() == "POST") {
        } else {
          let html = view.compileFile("./tamplate/form_update.html")();
          res.writeHead(200, { "Contact-Type": "text/html" });
          res.end(html);
        }
      } else {
        let html = view.compileFile("./tamplate/form_update.html")();
        res.writeHead(200, { "Contact-Type": "text/html" });
        res.end(html);
      }
    }
  );


});

please help me i have no idea

Upvotes: 0

Views: 37

Answers (1)

Arif Oyong
Arif Oyong

Reputation: 432

I think it's better to use router.post

For example:

router.post("/update/:id", (req, res) => {
  conn.query(
    "select * from mahasiswa where ? ",
    { no_induk: req.params.id },
    function (err, rows, field) {
      if (rows.length) {
          let html = view.compileFile("./tamplate/form_update.html")();
          res.writeHead(200, { "Contact-Type": "text/html" });
          res.end(html);
        }
      }
});

Upvotes: 1

Related Questions