请帮助我解决这个错误,我长期以来一直在努力解决它。因此,我也无法将数据添加到我的数据库中。任何帮助将不胜感激。这是我的index.js代码这是我的routes.js代码const { con, sessionStore } = require('./config/db');exports.new = function(req, res){ message = ''; if(req.method == "POST"){ const post = req.body; const username= post.username; const title= post.title; const state= post.state; const category= post.category; const description= post.description; if (!req.files) return res.status(400).send('No files were uploaded.'); const file = req.files.uploads; const img_name=file.name; if(file.mimetype == "images/jpeg" ||file.mimetype == "images/png"||file.mimetype == "images/gif" ){ file.mv('public/imgs/uploads/'+file.name, function(err) { if (err) return res.status(500).send(err); const sql = "INSERT INTO `nt_data`(`username`,`title`,`state`,`category`, `images` ,`description`) VALUES ('" + username + "','" + title + "','" + state + "','" + category + "','" + img_name + "','" + description + "')"; const query = con.query(sql, function(err, result) { res.redirect('show/'+result.insertUsername); }); }); } else { message = "This format is not allowed , please upload file with '.png','.gif','.jpg'"; res.render('new.ejs',{message: message}); } } else { res.render('new'); } };exports.show = function(req, res){ let message = ''; const username = req.params.username; const sql="SELECT * FROM `nt_data` WHERE `username`='"+username+"'"; con.query(sql, function(err, result){ if(result.length <= 0) message = "show not found!"; res.render('show.ejs',{data:result, message: message}); });};请帮我解决这个错误,这非常重要。谢谢
1 回答
蝴蝶刀刀
TA贡献1801条经验 获得超8个赞
您的index.js 文件不包含路由的 POST 方法"/"
。您可以使用以下示例添加一个:
app.post('/',function(req,res){ //Your function code });
添加回答
举报
0/150
提交
取消