2 글 보임 - 1 에서 2 까지 (총 2 중에서)
-
글쓴이글
-
2022년 7월 3일 22:50 #37936
Heok Joon참가자sever.js
app.get("/edit/:id", function (request, response) { db.collection("post").findOne( { _id: parseInt(request.params.id) }, function (error, result) { console.log(result); response.render("edit.ejs", { post: result }); } ); }); //어떤사람이 /edit경로로 put요청을 하면은 폼에 담긴 제목 데이터, // 날짜 데이터를 가지고 db.collection에다가 업데이트함 app.put("/edit", function (request, response) { db.collection("post").updateOne( { _id: parseInt(request.body.id) }, { $set: { 이름: request.body.id, 비번: request.body.password } }, function (error, result) { console.log("수정완료"); response.redirect("/list"); } ); }); ------------------ edit.ejs
<!DOCTYPE html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" />
<title>Hello, world!</title> </head> <body> <%- include('nav.html') %> <div class="container"> <form action="/add?_method=PUT" method="POST"> <div class="form-group"> <label for="exampleInputEmail1">Email address</label> <input value="<%=post._id%>" type="" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" name="id" /> <small id="emailHelp" class="form-text text-muted" >We'll never share your email with anyone else.</small > </div> <div class="form-group"> <label for="exampleInputPassword1">Password</label> <input value="<%=post.비번%>" type="" class="form-control" id="exampleInputPassword1" name="password" /> </div> <div class="form-group form-check"> <input type="checkbox" class="form-check-input" id="exampleCheck1" name="체크박스" /> </div> <button type="submit" class="btn btn-danger">Submit</button> </form> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous" ></script> </body> </html>
이상하게 write로 넘어가서 다음번호가 새겨지고 새로운 데이터가 만들어져서 위에는 주석처리하고 아래에서 바꾸려해봐도, name 비교해봐도, 뭔때문에 Cannot get 을 받는지 모르겠네요
-
글쓴이글
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
- 답변은 로그인 후 가능합니다.