choi

add write function in board

var express = require('express');
const { connect } = require('http2');
var router = express.Router();
var mysql = require('mysql');
var path = require('path') // 상대경로
......@@ -6,7 +7,7 @@ var mysql_odbc = require('../../db/db_board')();
var board = mysql_odbc.init();
router.get('/:page', function(req, res, next) {
router.get('/list/:page', function(req, res, next) {
var page = req.params.page;
var sql = "select idx, name, title, date_format(modidate,'%Y-%m-%d %H:%i:%s') modidate, " +
"date_format(regdate,'%Y-%m-%d %H:%i:%s') regdate from board";
......@@ -18,8 +19,26 @@ router.get('/:page', function(req, res, next) {
})
});
router.get('/', function(req,res,next){
res.redirect('/board/1')
router.get('/list', function(req,res,next){
res.redirect('/board/list/1')
})
router.get('/write', function(req,res,next){
res.render('write.ejs', {title:"게시판 글 쓰기"})
})
router.post('/write', function(req,res,next){
var name = req.body.name
var title = req.body.title
var content = req.body.content
var passwd = req.body.passwd
var datas = [name,title,content,passwd]
var sql = "insert into board(name, title, content, regdate, modidate, passwd,hit) values(?,?,?,now(),now(),?,0)";
board.query(sql,datas, function (err, rows) {
if (err) console.error("err : " + err);
res.redirect('/board/list/1');
});
})
module.exports = router;
\ No newline at end of file
......
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css'/>
</head>
<body>
<h1><%= title %></h1>
<form action="/board/write" method="post">
<table border="1">
<tr>
<td>작성자</td>
<td><input type="text" name="name" id="name" required/></td>
</tr>
<tr>
<td>제목</td>
<td><input type="text" name="title" id="title" required/></td>
</tr>
<tr>
<td>내용</td>
<td><textarea name="content" id="content" cols="30" rows="10" required></textarea></td>
</tr>
<tr>
<td>패스워드</td>
<td><input type="password" name="passwd" id="passwd" required/></td>
</tr>
<tr>
<td colspan="2">
<button type="submit">글쓰기</button>
</td>
</tr>
</table>
</form>
</body>
</html>
\ No newline at end of file