請(qǐng)幫助我解決這個(gè)錯(cuò)誤,我長(zhǎng)期以來(lái)一直在努力解決它。因此,我也無(wú)法將數(shù)據(jù)添加到我的數(shù)據(jù)庫(kù)中。任何幫助將不勝感激。這是我的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}); });};請(qǐng)幫我解決這個(gè)錯(cuò)誤,這非常重要。謝謝
無(wú)法 POST / Nodejs
楊__羊羊
2023-09-14 20:45:24