创建警报并在警报后继续在此页面上

时间:2011-05-06 12:47:12

标签: php javascript sql postgresql

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

               guid                | username |             password             | firstname | lastname  | location | emailad
dress |   userrole
-----------------------------------+----------+----------------------------------+-----------+-----------+----------+--------
------+---------------
 8024259764dc3e8ee0fb6f5.84107784  | james    | 827ccb0eea8a706c4c34a16891f84e7b | james     | bond      | NY       | ny@live
.com  | administrator
 18689183644dc3e91571a364.71859328 | saty     | 250cf8b51c773f3f8dc8b4be867a9a02 | saty      | john      | NY       | hk@fd.c
om    | 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

(1)当我逐个删除用户名然后删除发生在我的页面userlist.php中,我不想删除admin,所以我在where条件中使用username!= 'admin',如上所示。 (2)现在当我从用户表中删除任何用户名(3行)时,就会发生警报&amp;在我的页面userlist.php为空后,它从userlist.php中删除。最后,当我刷新页面,然后看到我的管理员用户名..

所以任何人都可以将最好的条件放在我的编码中。 我不想刷新页面,我希望我的页面在提醒后继续,以便plz帮助我

2 个答案:

答案 0 :(得分:0)

我的猜测是你在删除后不执行SELECT查询。确保您的列表低于删除查询,因此您的页面将类似于

if($_GET['delete']) {
  // delete query
}

$sql = "SELECT * FROM";
// rest for getting the complete list.

这样你就可以获得刷新清单..

//编辑: 哦,并且可能在警报可能继续执行页面之后添加return true;,因为javascript可能阻止进一步执行警报(不确定它是否默认返回false)。

答案 1 :(得分:0)

使用此

$query = "select username from users where username='admin' and guid='".$guid."'";  
    $result = pg_query($conn, $query);
    AddLog("deleteUI.php","Query : ".$query,ERR_DEBUG_HIGH);
    while ($row = pg_fetch_array($result)) 

    //if (pg_affected_rows($result))
        {
            AddLog("deleteUI.php","Error !!! COMMIT",ERR_DEBUG_HIGH);
            pg_close($conn);
            ?>      
        <script type="text/javascript">            
        alert("Cannot delete the built-in admin user.");
        </script>           
        <?php 
        exit();
        } 

&安培;删除那样的查询

$query = "delete from users where guid='".$guid."'";