删除所有确认php

cma*_*rio 0 php mysql

我有一个表预览我的数据库表中的所有记录.我做了一个按钮,当它被点击时,给定表的所有记录都被删除.我只是想在用户点击全部删除后立即添加确认消息.

deleteall.php

// get the 'id' variable from the URL
$id = $_GET['id'];
$table = $_GET['table'];
mysqli_query($con,"DELETE FROM $table");
Run Code Online (Sandbox Code Playgroud)

链接(在另一个PHP文件中)

echo "<td><a href='../cms/deleteall.php?id=" . "&table=" . $table .  "'>Delete All</a></td>";
Run Code Online (Sandbox Code Playgroud)

有什么建议?

Nie*_*sol 7

AAAHHH!您是否正在使用GET - 不仅要更改内容,还要 - 从服务器中删除内容?NONONO,这是BAD!

所有在服务器上进行更改的请求都应该是POST请求.像这样:

<td><form action="../cms/deleteall.php" method="post">
    <input type="hidden" name="id" value="<?=$id?>" />
    <input type="hidden" name="table" value="<?=$table?>" />
    <input type="submit" onClick="return confirm('Are you SURE you want to delete everything?');" value="Delete All" />
</form></td>
Run Code Online (Sandbox Code Playgroud)

另外,确认!我可以非常轻松地将请求更改为delete=users甚至delete=otherdatabase.tablename只是因为您尚未验证它,并擦除服务器上的所有数据!要非常小心!