gpt4 book ai didi

php - 为特定行 1 创建警报,而不是从数据库 postgre 中删除

转载 作者:行者123 更新时间:2023-12-02 20:18:19 24 4
gpt4 key购买 nike

我有一个像这样的用户表:-

               guid                | username |             password             | firstname | lastname  | location | emailaddress |   userrole
-----------------------------------+----------+----------------------------------+-----------+-----------+----------+--------------+---------------
8024259764dc3e8ee0fb6f5.84107784 | james | 827ccb0eea8a706c4c34a16891f84e7b | james | bond | NY | ny@live.com | administrator
18689183644dc3e91571a364.71859328 | saty | 250cf8b51c773f3f8dc8b4be867a9a02 | saty | john | NY | hk@fd.com | administrator
2644885344cecd6f2973b35.63257615 | admin | 21232f297a57a5a743894a0e4a801fc3 | System | Generated | | | administrator
(3 rows)

现在我的 postgre 查询删除该行....

$query = "delete from users where username!= 'admin' and guid='".$guid."'";
$result = pg_query($conn, $query);

?>
<script type="text/javascript">
alert("Cannot delete this .\n It is system generated(s).");
</script>
<?php

当有人尝试从我的页面 userlist.php 中删除用户名时..此警报仅针对管理员生成并继续在此页面上..并且管理员永远不会删除它是默认的...否则从数据库中删除除 admin 之外的数据帮助我

最佳答案

为什么不在尝试删除任何内容之前查找 $guid 的用户名,只需一段简单的 SQL,如下所示:

$query = "select username from users where guid = '" . $guid . "'";
# Execute this, pull out the username, and see if it is "admin".

然后,如果用户名是“admin”,则显示您的警报;如果用户名不是“admin”,请进行删除。当您应该一次只做一件事情时,您似乎试图同时做太多不同的事情,当您需要做两件不同的事情时,执行两个查询并没有什么问题。

我希望您在某处清理并引用 $guid 以防止 SQL 注入(inject)问题。

关于php - 为特定行 1 创建警报,而不是从数据库 postgre 中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5919720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com