PHP 和 HTML 删除

发布于 2024-12-08 08:52:26 字数 1469 浏览 7 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

热情消退 2024-12-15 08:52:26

您需要将要删除的记录的 ID 添加到删除 url,例如:

echo "<td><a href=\"delete.php\?id={$row['ID']}">Delete</a></td>";

然后,在您的 delete.php 脚本中,您需要执行以下操作:

<?php

$id = intval($_GET['id']);
$sql = "DELETE FROM yourtable WHERE id=$id";
$result = mysql_query(sql);

当然,这不是完整的脚本,但向您展示了基本知识需要完成。在查询中使用传入的值时要小心 - 不想让 SQL 注入漏洞毁了您的一天。

但是,请注意,对此类事情使用“GET”类型查询通常是一个坏主意。如果此页面被 Google 抓取(仅此而已),您会发现简单的抓取行为就毁掉了您的所有记录。

You need to add the ID of the record you want to delete to the delete url, e.g.:

echo "<td><a href=\"delete.php\?id={$row['ID']}">Delete</a></td>";

Then, in your delete.php script, you'd do:

<?php

$id = intval($_GET['id']);
$sql = "DELETE FROM yourtable WHERE id=$id";
$result = mysql_query(sql);

Of course, that's not a full script, but shows you the basics of what needs to be done. Be careful with using the passed-in value in your query - don't want to let an SQL injection hole ruin your day.

However, be aware that using a 'GET' type query for this sort of thing is generally a bad idea. If this page gets spidered by Google (for one), you'll find that the simple act of spidering has nuked ALL of your records.

ぺ禁宫浮华殁 2024-12-15 08:52:26

您需要将行的 ID 作为参数传递给 delete.php 脚本

echo "<td>" . '<a href="delete.php?'.$row['ID'].'">Delete</a>' . "</td>";

You need to pass the ID of the row as paramter to the delete.php script

echo "<td>" . '<a href="delete.php?'.$row['ID'].'">Delete</a>' . "</td>";
久随 2024-12-15 08:52:26

您可以使用当前行的id并将其发送到delete.php:

 echo "<td>" . '<a href="delete.php?id='.$row['ID'].'">Delete</a>' . "</td>";

然后在delete.php中通过 $deleteId = $_GET['id'] 获取id并使用它...

you can use the id of the current row and send it to delete.php:

 echo "<td>" . '<a href="delete.php?id='.$row['ID'].'">Delete</a>' . "</td>";

then in delete.php get the id by $deleteId = $_GET['id'] and use it...

金橙橙 2024-12-15 08:52:26

尝试将 URL 更改为 echo ''

顺便说一句 - 这不是一个好主意使用root!

Try changine the URL to something like echo '<a href="delete.php?ID=' . $row['ID'] . '">'

BTW - Not a good idea to use root!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文