我无法从Mysql数据库中删除表格行。当我点击网站上的“删除”按钮时,它必须从该行中完全删除内容。这是我的代码:
Index.ejs:
<% if(pictures.length){ %>
<table style="width:100%">
<tr>
<th>Image</th>
<th>Driver</th>
<th>Team</th>
<th>Location</th>
<% if(admin) { %>
<th>Edit</th>
<th>Delete</th>
<% } %>
</tr>
<% } %>
<% for (var i = 0; i < pictures.length; i++) { %>
<tr>
<td><img src="images/<%= pictures[i].image %>" /></td>
<td><%= pictures[i].driver %></td>
<td><%= pictures[i].team %></td>
<td><%= pictures[i].location %></td>
<% if(admin) { %>
<td><a href="edit/<%= pictures[i].id %>" >Edit</a></td>
<td><a href="/<%= pictures[i].id %>">Delete</a></td>
<% } %>
<% } %>
</tr>
</table>
</div>
edit.js:
router.get('/:id', function(req, res) {
var id = req.params.id;
req.getConnection(function (err, connection) {
connection.query("DELETE FROM pictures WHERE id = ? ", [id], function(err, results) {
res.redirect('/');
console.log('Some data has been deleted')
});
});
});
这是我得到的错误:
不能GET / 10 (10是该表中的ID)
提前致谢!