choi

add bulletin delete function

......@@ -105,4 +105,26 @@ router.post('/update', function(req,res,next){
})
})
router.post('/delete', function(req,res,next){
var idx = req.body.idx
var passwd = req.body.passwd
var datas = [idx,passwd]
var sql = "delete from board where idx=? and passwd=?"
board.query(sql,datas, function(err,result){
if(err) console.error(err)
if(result.affectedRows == 0){
res.send("<script>alert('패스워드가 일치하지 않습니다.');history.back();</script>");
}
else
{
var id = req.user.ID;
var nickname = req.user.nickname;
console.log(req.user.ID+'('+nickname+') 유저가 '+idx+'번 게시글을 삭제했습니다.')
res.redirect('/board/list/');
}
})
})
module.exports = router;
\ No newline at end of file
......
......@@ -31,7 +31,13 @@
</nav>
<div class="container px-5 my-5">
<h1><%= title %></h1>
<script>
function submit2(frm){
frm.action="/board/delete";
frm.submit();
return true;
}
</script>
<form action="/board/update" method="post">
<table border="1">
<input type="hidden" name="idx" value="<%=row.idx%>"/>
......@@ -64,8 +70,9 @@
<td><%=row.hit%></td>
</tr>
<tr>
<td colspan="2">
<td colspan="3">
<button type="submit">글 수정</button>
<button type="summit" onclick="return submit2(this.form);">글 삭제</button>
<a href="/board/list">목록</a>
</td>
</tr>
......@@ -102,6 +109,7 @@
</ul>
</div>
</div>
</div>
</footer>
</body>
......