0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

◆削除機能をつける 削除ボタンの準備

①ルーティングを用意
app.post('/delete',(req,res) => {
処理
});

②削除ボタンを用意

③リダイレクト
app.post('/delete',(req,res) => {
res.redirect('/index');
});

◆削除の処理
①index.ejs

②app.js

app.post('/delete/:id',(req,res) => {
res.redirect('/index');
});

◆受け取った値をクエリで実行しよう

app.post('/delete/:id', (req,res) => {
connection.query(
'DELETE FROM items WHERE id = ?',
[req.params.id],
(error,result) => {
res.redirect('/index');
}
)
});

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?