Showing
2 changed files
with
61 additions
and
3 deletions
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | +const { connect } = require('http2'); | ||
2 | var router = express.Router(); | 3 | var router = express.Router(); |
3 | var mysql = require('mysql'); | 4 | var mysql = require('mysql'); |
4 | var path = require('path') // 상대경로 | 5 | var path = require('path') // 상대경로 |
... | @@ -6,7 +7,7 @@ var mysql_odbc = require('../../db/db_board')(); | ... | @@ -6,7 +7,7 @@ var mysql_odbc = require('../../db/db_board')(); |
6 | var board = mysql_odbc.init(); | 7 | var board = mysql_odbc.init(); |
7 | 8 | ||
8 | 9 | ||
9 | -router.get('/:page', function(req, res, next) { | 10 | +router.get('/list/:page', function(req, res, next) { |
10 | var page = req.params.page; | 11 | var page = req.params.page; |
11 | var sql = "select idx, name, title, date_format(modidate,'%Y-%m-%d %H:%i:%s') modidate, " + | 12 | var sql = "select idx, name, title, date_format(modidate,'%Y-%m-%d %H:%i:%s') modidate, " + |
12 | "date_format(regdate,'%Y-%m-%d %H:%i:%s') regdate from board"; | 13 | "date_format(regdate,'%Y-%m-%d %H:%i:%s') regdate from board"; |
... | @@ -18,8 +19,26 @@ router.get('/:page', function(req, res, next) { | ... | @@ -18,8 +19,26 @@ router.get('/:page', function(req, res, next) { |
18 | }) | 19 | }) |
19 | }); | 20 | }); |
20 | 21 | ||
21 | -router.get('/', function(req,res,next){ | 22 | +router.get('/list', function(req,res,next){ |
22 | - res.redirect('/board/1') | 23 | + res.redirect('/board/list/1') |
24 | +}) | ||
25 | + | ||
26 | +router.get('/write', function(req,res,next){ | ||
27 | + res.render('write.ejs', {title:"게시판 글 쓰기"}) | ||
28 | +}) | ||
29 | + | ||
30 | +router.post('/write', function(req,res,next){ | ||
31 | + var name = req.body.name | ||
32 | + var title = req.body.title | ||
33 | + var content = req.body.content | ||
34 | + var passwd = req.body.passwd | ||
35 | + var datas = [name,title,content,passwd] | ||
36 | + | ||
37 | + var sql = "insert into board(name, title, content, regdate, modidate, passwd,hit) values(?,?,?,now(),now(),?,0)"; | ||
38 | + board.query(sql,datas, function (err, rows) { | ||
39 | + if (err) console.error("err : " + err); | ||
40 | + res.redirect('/board/list/1'); | ||
41 | + }); | ||
23 | }) | 42 | }) |
24 | 43 | ||
25 | module.exports = router; | 44 | module.exports = router; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
views/write.ejs
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html> | ||
3 | +<head> | ||
4 | + <title><%= title %></title> | ||
5 | + <link rel='stylesheet' href='/stylesheets/style.css'/> | ||
6 | +</head> | ||
7 | +<body> | ||
8 | +<h1><%= title %></h1> | ||
9 | + | ||
10 | + | ||
11 | +<form action="/board/write" method="post"> | ||
12 | + <table border="1"> | ||
13 | + <tr> | ||
14 | + <td>작성자</td> | ||
15 | + <td><input type="text" name="name" id="name" required/></td> | ||
16 | + </tr> | ||
17 | + <tr> | ||
18 | + <td>제목</td> | ||
19 | + <td><input type="text" name="title" id="title" required/></td> | ||
20 | + </tr> | ||
21 | + <tr> | ||
22 | + <td>내용</td> | ||
23 | + <td><textarea name="content" id="content" cols="30" rows="10" required></textarea></td> | ||
24 | + </tr> | ||
25 | + <tr> | ||
26 | + <td>패스워드</td> | ||
27 | + <td><input type="password" name="passwd" id="passwd" required/></td> | ||
28 | + </tr> | ||
29 | + <tr> | ||
30 | + <td colspan="2"> | ||
31 | + <button type="submit">글쓰기</button> | ||
32 | + </td> | ||
33 | + </tr> | ||
34 | + </table> | ||
35 | +</form> | ||
36 | + | ||
37 | + | ||
38 | +</body> | ||
39 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment