2016-07-05 86 views
-5

因此,我正在PHP 5.6admin面板功能和每當我嘗試將用戶切換到管理它將它們設置爲生成器我不知道在哪裏或我在做什麼錯 下面是代碼不知道爲什麼這不起作用(PHP)

這是updateusera.php

 <?php include 'core/init.php'; 


$id = $_GET['id']; 
$type = $_GET['type']; 

if($type == 'admin'){ 
    mysql_query("UPDATE `users` SET `type` = 'user' WHERE `user_id` = '$id'"); 
    header('location: changeusers.php'); 

} else if($type =='user'){ 
    mysql_query("UPDATE `users` SET `type` = 'admin' WHERE `user_id` = '$id'"); 
    header('location: changeusers.php'); 

} 

// ======================== =================================================

if($type == 'moderator'){ 
    mysql_query("UPDATE `users` SET `type` = 'user' WHERE `user_id` = '$id'"); 
    header('location: changeusers.php'); 

} else if($type =='user'){ 
    mysql_query("UPDATE `users` SET `type` = 'moderator' WHERE `user_id` = '$id'"); 
    header('location: changeusers.php'); 

} 

// ============================================== ===========================

if($type == 'builder'){ 
    mysql_query("UPDATE `users` SET `type` = 'user' WHERE `user_id` = '$id'"); 
    header('location: changeusers.php'); 

} else if($type =='user'){ 
    mysql_query("UPDATE `users` SET `type` = 'builder' WHERE `user_id` = '$id'"); 
    header('location: changeusers.php'); 

} 
?> 

this is the changeusers.php file 

http://pastebin.com/qR2VybTk

由於某種原因,它不會讓我把兩個我在這裏PS碼我新的所以我仍然得到使用,以StackOverflow的這一切

如果任何人有一個想法,我很樂意聽到它

謝謝!

+2

首先,你有兩個主要問題。 1.您正在使用不推薦使用的'mysql_ *'函數(自PHP 5.5起棄用,並在PHP 7中刪除)。 2. [SQL注入](http://php.net/manual/en/security.database.sql-injection.php)是開放的。我建議更改爲Mysqli或首選的PDO,然後使用Prepared Statements。 –

+0

來自我的簡單問題。當你回聲$ _GET ['type']' – YVS1102

+0

我得到了PHP的第一個使用,所以我正在建立這個更好的它,我也有很多其他文件,所以當我得到我將開始轉換爲mysqli – Darktornado23

回答

0

您有三個else if陳述,即當$type =='user'true。這些else if中的一切都執行併發送三個查詢,其中最後一個設置了類型生成器。

您需要傳入您需要設置的參數類型。這樣的話:

if($type == 'admin') { 
    echo "<a href='updateusera.php?id=&type=user'>Revoke Admin </a>"; 
} else { 
    echo "<a href='updateusera.php?id=$id&type=admin'>Grant Admin </a>"; 
} 
if($type == 'moderator') { 
    echo "<a href='updateusera.php?id=$id&type=user'>Revoke Moderator </a>"; 
} else { 
    echo "<a href='updateusera.php?id=$id&type=moderator'>Grant Moderator </a>"; 
} 
if($type == 'builder') { 
    echo "<a href='updateusera.php?id=$id&type=user'>Revoke Builder</a>"; 
} else { 
    echo "<a href='updateusera.php?id=$id&type=builder'>Grant Builder</a>"; 
} 

然後,你的代碼必須是這樣的:

if($type == 'user') { 
    mysql_query("UPDATE `users` SET `type` = 'user' WHERE `user_id` = '$id'"); 
    header('location: changeusers.php'); 
    exit; 
} 
if($type == 'admin') { 
    mysql_query("UPDATE `users` SET `type` = 'admin' WHERE `user_id` = '$id'"); 
    header('location: changeusers.php'); 
    exit; 
} 
if($type == 'builder') { 
    mysql_query("UPDATE `users` SET `type` = 'builder' WHERE `user_id` = '$id'"); 
    header('location: changeusers.php'); 
    exit; 
} 
+0

那麼我應該怎樣改變我的'else if's'? – Darktornado23

+0

我加了出口的 – Darktornado23

+0

現在工作正確嗎? –

0

你想改變你的else if語句if語句;基本上所有的else if語句正在執行,並且最後的else if語句被設置爲構建器。

+0

我應該如何設置它們? – Darktornado23

相關問題