죄송합니다, 이러한 질문은 대중적이지만 그곳에 대한 답변을 찾을 수 없습니다. 특급의 재산을 읽을 수 없습니다
은 바로 그런 질문이, 스크롤하기위한const express = require('express');
const router = express.Router();
router.get('/', function (req, res, next) {
let query = 'select event.id, event.title, event.description, event.date, place.title as place, organisator.title as organisator, subcategory.title as subcategory from ((event inner join place on event.place_id = place.id) inner join organisator on event.organisator_id = organisator.id) inner join subcategory on event.subcategory_id = subcategory.id';
res.locals.connection.query(query, function (error, results, fields) {
if (error) throw error;
res.render('index', { title: 'Events', data: results });
});
});
router.post('/add', function (err, req, res) {
const query = "insert into event (title, description, event.date, subcategory_id, place_id, organisator_id) values ('" + req.body.title + "','" + req.body.description + "','" + req.body.date + "',(SELECT id from subcategory WHERE title = '" + req.body.subcategory + "'),(SELECT id from place WHERE title = '" + req.body.place + "'),(SELECT id from organisator WHERE title = '" + req.body.organisator + "'))";
connection.query(query, function (err) {
if (err) {
console.error(err);
throw err;
}
});
});
죄송합니다이 파일에 요청을 게시 링크 정의되지 않은
의 특성 '제목'을 읽을 수 없습니다
출력
되세요. body-parser가 어떤 것보다 먼저 사용해야한다는 답변을 찾았지만 그런 문제가 없다고 생각합니다. 내 앱 파일이 있습니다.const express = require('express'); const path = require('path'); const logger = require('morgan'); const bodyParser = require('body-parser'); var app = express(); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(logger('dev')); app.use(express.static(path.join(__dirname, 'public'))); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); var mysql = require("mysql"); app.use(function(req, res, next){ res.locals.connection = mysql.createConnection({ host : 'localhost', user : 'root', password : 'Strange3865hum31315', database : 'minskevents' }); res.locals.connection.connect(); next(); }); app.use('/', require('./routes/index')); app.use('/events', require('./routes/events')); app.use(function(req, res, next) { var err = new Error('Not Found'); err.status = 404; next(err); }); app.use(function(err, req, res, next) { res.locals.message = err.message; res.locals.error = req.app.get('env') === 'development' ? err : {}; res.status(err.status || 500); res.render('error'); }); var http = require('http'); var server = http.createServer(app); server.listen(4000); if(server.listening){ console.log('Server is listening on port 4000'); } module.exports = app;
나는 표현의
<form action="/events/add" method="POST"> <input type="text" name="title" placeholder="Event name" /> <input type="text" name="subcategory" placeholder="Category" /> <input type="text" name="date" placeholder="Date" /> <input type="text" name="place" placeholder="Place" /> <input type="text" name="organisator" placeholder="Organisator" /> <textarea name="description" placeholder="Description" onkeyup="adjust_textarea(this)"></textarea> <input type="submit" value="Add" /> </form>
'POST'요청 함수에서 첫 번째 인수로'err'을 제거하십시오. 대신'(req, res, next) '를 사용하십시오. – oneturkmen