前提・実現したいこと
htmlのformに入力した値をnode.jsで受け取りたい
TypeError: Cannot read property 'subject' of undefined at C:\Users\r.yama\Desktop\study_time.ver2.0\app.js:53:17 at Layer.handle [as handle_request] (C:\Users\r.yama\Desktop\study_time.ver2.0\node_modules\express\lib\router\layer.js:95:5) at next (C:\Users\r.yama\Desktop\study_time.ver2.0\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (C:\Users\r.yama\Desktop\study_time.ver2.0\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (C:\Users\r.yama\Desktop\study_time.ver2.0\node_modules\express\lib\router\layer.js:95:5) at C:\Users\r.yama\Desktop\study_time.ver2.0\node_modules\express\lib\router\index.js:281:22 at param (C:\Users\r.yama\Desktop\study_time.ver2.0\node_modules\express\lib\router\index.js:354:14) at param (C:\Users\r.yama\Desktop\study_time.ver2.0\node_modules\express\lib\router\index.js:365:14) at Function.process_params (C:\Users\r.yama\Desktop\study_time.ver2.0\node_modules\express\lib\router\index.js:410:3) at next (C:\Users\r.yama\Desktop\study_time.ver2.0\node_modules\express\lib\router\index.js:275:10)
該当のソースコード
javascript
1 <form action="/update/<%= studyTime.id %>" method="post"> 2 <input type="text" name="subject" value="<%= studyTime.subject %>" class='editTools'> 3 <input type="date" name="date" value="<%= y + '-' + m + '-' + d %>" class='editTools'> 4 <input type="time" name="time" value="<%= studyTime.time %>" class='editTools'> 5 <input type="submit" value="更新" class='editTools'> 6 </form> 7</body>
node
1app.post('/update/:id',(req,res)=>{ 2 connection.query( 3 'update users set subject = ?,date = ?,time = ? where id=?', 4 [req.body.subject,req.body.date,req.body.time,req.params.id], 5 (error,results)=>{ 6 res.redirect('/index'); 7 }); 8});
補足情報(FW/ツールのバージョンなど)
express version 4.17.1
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/08/25 07:51