• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Node.js, Express 게시판 회원정보수정 오류....

회원정보수정 오류....

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #31488

    냠냠냠
    참가자

    안녕하세요.

    배운 코드 바탕으로 회원정보수정을 페이지를 만들고 있습니다.

    글 수정과 비슷하게 들어가고 collection만 달라지는 것이라고 생각했는데, 오류페이지는 딱히 안 나오지만 db 들어가면 회원정보 수정이 안 되어있습니다.... 어디서 문제가 생기는지 모르겠습니다...

     

    server.js 에는

    //마이 페이지 내 정보 수정에 데이터 뿌리기
    app.get('/mypage/:id', function(요청, 응답) {
        db.collection('login').findOne({id : parseInt(요청.params.id)},function(에러, 결과){
            if(에러){return console.log(에러)};
            console.log(결과);
            응답.render('mypage.ejs', {user : 결과});
        });
    });

    //마이 페이지 내정보수정
    app.put('/mypage', function(요청, 응답){
       
        var 수정할데이터 = {id : 요청.body.id}
       
        if(db.collection('login').findOne({id : 요청.body.id})){
            bcrypt.hash(요청.body.pw, saltRounds, function (err, hash) {
               db.collection('login').updateOne(수정할데이터,{ $set : {email : 요청.body.email, pw : hash} },function(에러, 결과){
                if(에러){return console.log(에러)};
                console.log(결과);
                console.log('회원 정보 수정 완료');
                응답.send("<script>alert('회원 정보 수정이 완료되었습니다!'); window.location.replace('/mypage');</script>");
                })
            })
        }
    });

     

    이런 식으로 작성하였고,

     

     

    mypage.ejs 에는

        <h4 class="container mt-4 text-center"><strong>    <%= 사용자.id %> 님 회원 정보 수정 </strong></h4>
        <div class="container mt-3" style="width: 50%;">
          <form action="/mypage?_method=PUT" method="POST">
            <div class="form-group">
              <label>이메일 <%= 사용자.email %></label>
              <input type="email" value="<%= 사용자.email %>" class="form-control" name="email">
            </div>
            <div class="form-group">
              <label>비밀번호</label>
              <input id="pw" type="password" class="form-control" name="pw">
            </div>
            <div class="form-group">
              <label>비밀번호 재확인</label>
              <input id="pw_a" type="password" class="form-control" name="pwAgain">
            </div><br>
            <button type="submit" class="btn btn-outline-secondary">정보 수정</button>
           
          </form>
        </div>
           

     

    이렇게 작성하였습니다.

     

    콘솔에는 

     

    {
    _id: new ObjectId("62495b9101106e828c96ff38"),
    id: 'love',
    pw: '$2b$10$dGbuJArd4wlGB6dWduCDGePlynIgQnauxvf8NwEOXrp7tlKL/5OP.'
    }
    {
    acknowledged: true,
    modifiedCount: 0,
    upsertedId: null,
    upsertedCount: 0,
    matchedCount: 0
    }
    회원 정보 수정 완료
    {
    _id: new ObjectId("62495b9101106e828c96ff38"),
    id: 'love',
    pw: '$2b$10$dGbuJArd4wlGB6dWduCDGePlynIgQnauxvf8NwEOXrp7tlKL/5OP.'
    }

     

    이렇게 출력되고 있습니다.

    수정 완료라는 콘솔로그가 나와서 된 줄 알았는데 db 들어가서 확인해보니 정보가 바뀌지 않았습니다... 코드를 여기서 어떻게 수정을 해야 할까요?? 도움 부탁드립니다...

    #31512

    codingapple
    키 마스터

     var 수정할데이터 이런거부터 잘 들어오는지 출력해봅시다 

    없다면 프론트엔드에서 잘못보내거나 그런경우라 ejs파일 수정하면 됩니다 

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠