Promote User and Notify Them


This tutorial is very easy to follow. First open Notepad++ and type in this.

PHP Code
  1. <?php
  2. include("config.php");
  3. if($logged[username] && $logged[userlevel] == 6) {
  4. switch($_GET['promote']) {
  5.  
  6. default:
  7. echo "<form action='?promote=user' method='post'>
  8. Username: <input type='text' name='user'>
  9. Level: <select name='level'>
  10. <option value='0'>Banned</option>
  11. <option value='1'>Unvalidated user</option>
  12. <option value='2'>Validated User</option>
  13. <option value='4'>Moderator</option>
  14. <option value='6'>Administrator</option>
  15. </select>
  16. <input type='submit' value='Submit'></form>";
  17. break;
  18.  
  19. case 'user':
  20. $admin = $_POST['user'];
  21. $level = $_POST['level'];
  22.  
  23. $update = mysql_query("UPDATE `members` SET `userlevel` = '$level' WHERE `username` = '$admin'");
  24. if ($_POST['level'] == 6)
  25. {
  26. //start private message
  27. $to = $admin; //get who it is to
  28. $from = 'Bot'; //who its from
  29. $subject = "Promotion!"; //new subject
  30. $msg = "Hello, $admin! $logged[username] promoted you to an Administrator!"; //the content
  31. $date = date("F j, Y, g:i a"); //the date sent
  32. $do = mysql_query("INSERT INTO `privates` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $to . "','" . $from . "','" . $date . "','" . $subject . "','" . $msg . "')") or die(mysql_error()); //insert into the table!
  33. //end private message
  34. }
  35. if ($_POST['level'] == 4)
  36. {
  37. //start private message
  38. $to = $admin; //get who it is to
  39. $from = 'Bot'; //who its from
  40. $subject = "Promotion!"; //new subject
  41. $msg = "Hello, $admin! $logged[username] promoted you to a Moderator!"; //the content
  42. $date = date("F j, Y, g:i a"); //the date sent
  43. $do = mysql_query("INSERT INTO `privates` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $to . "','" . $from . "','" . $date . "','" . $subject . "','" . $msg . "')") or die(mysql_error()); //insert into the table!
  44. //end private message
  45. }
  46. echo "$admin is now a $level.";
  47. break;
  48. }
  49. }
  50. ?>


Viola. Then press CTRL+S to save it as... promote.php

Then add to your site. That easy! Also the user will be notified by PM if they have been promoted (to mod or admin).
UrbanTwitch's Avatar
Views:
3,581
Rating:
Posted on Wednesday 23rd July 2008 at 08:07 PM
UrbanTwitch
UrbanTwitch's Avatar
Because the $_POST['user']; is where you promote the user so $_POST['user']; is same as $admin which goes to $to so it knows who to send it to!
Posted on Wednesday 23rd July 2008 at 07:03 PM
Diablosblizz
Diablosblizz's Avatar
What's the point of $to, as it's the SAME thing as $admin.
Posted on Wednesday 23rd July 2008 at 05:22 PM
UrbanTwitch
UrbanTwitch's Avatar
Snippits?
Posted on Wednesday 23rd July 2008 at 03:39 PM
ilyas-shezad
ilyas-shezad's Avatar
Not bad not bad... Daniel you need snippets section for next RMB version :p
Posted on Wednesday 23rd July 2008 at 02:59 PM
UrbanTwitch
UrbanTwitch's Avatar
At first I tested it out as Administrator. I forgot to change.
Posted on Wednesday 23rd July 2008 at 02:12 PM
MrArmstrong
MrArmstrong's Avatar
ok cool i like it :P
Posted on Wednesday 23rd July 2008 at 07:38 AM
darklight19
darklight19's Avatar
$msg = "Hello, $admin! $logged[username] promoted you to a Moderator!"; //the content

What's with $admin?