2011-05-06 38 views
1

後,我有一個用戶表是這樣的: -創建警報並繼續在此頁上的警報

   guid    | username |    password    | firstname | lastname | location | emailad 
dress | userrole 
-----------------------------------+----------+----------------------------------+-----------+-----------+----------+-------- 
------+--------------- 
8024259764dc3e8ee0fb6f5.84107784 | james | 827ccb0eea8a706c4c34a16891f84e7b | james  | bond  | NY  | [email protected] 
.com | administrator 
18689183644dc3e91571a364.71859328 | saty  | 250cf8b51c773f3f8dc8b4be867a9a02 | saty  | john  | NY  | [email protected] 
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,我不想刪除管理員,所以我使用username!= 'admin'在哪裏條件如上所示。 (2)現在當我從用戶表中刪除任何用戶名(3行)然後發生警報&它刪除userlist.php後,我的頁面userlist.php爲空。最後,當我刷新頁面,然後看到我的管理員用戶名..

所以任何人都可以把最好的條件放在我的編碼中。 我不想刷新頁面實際上我希望我的頁面繼續提醒後,所以PLZ幫助我

+0

可能重複(HTTP:// stackoverflow.com/questions/810180/how-to-prevent-deletion-of-the-first-row-in-table-postgresql) – 2011-05-06 13:35:04

+1

這看起來驚人地類似於: http://stackoverflow.com/questions/5908897/查詢換我-F irst-row-admin-for-never-delete and http://stackoverflow.com/questions/810180/how-to-prevent-deletion-of-the-first-row-in-table-postgresql – 2011-05-06 13:36:16

回答

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."'"; 
0

我的猜測是,你不會執行刪除後的SELECT查詢。確保您的列表下方的刪除查詢,讓您的網頁將類似於

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

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

這樣,你應該把你的刷新列表..

//編輯: 哦,也許以後加入return true;警報可能會繼續執行該頁面,因爲javascript可能會阻止對警報的進一步執行(不確定它是否默認返回false)。 [?如何防止第一行的缺失表(PostgreSQL的)