Admin Panel

Posted on Thursday 31st May 2007 at 08:28 AM
SkillMaster
SkillMaster's Avatar
PHP Code
  1. <?php
  2. session_start();
  3. include "config.php";
  4. if($logged[username] && $logged[level] == 6)
  5. {
  6. switch($_GET[page])
  7. {
  8. default:
  9. $fetch = mysql_query("SELECT * FROM `members` ORDER BY username ASC");
  10. while($users = mysql_fetch_array($fetch))
  11. {
  12. echo ("<a href='?page=edit&member=$users[username]'>- $users[username]</a><br>");
  13. }
  14. break;
  15.  
  16. case 'edit':
  17. $member = $_GET[member];
  18. $user = mysql_query("SELECT * FROM `members` where username = '$member'");
  19. $users = mysql_fetch_array($user);
  20. echo ("
  21. <form method='POST'>
  22. <table width='100%'>
  23. <tr>
  24. <td align='right' width='25%'>
  25. User Level</td>
  26. <td align='left'>
  27. <select name='level'>
  28. <option value='2'>User</option>
  29. <option value='4'>Mod</option>
  30. <option value='6'>Admin</option>
  31. </select> </td>
  32. </tr>
  33. <tr>
  34. <td align='right' width='25%'>
  35. Email</td>
  36. <td align='left'>
  37. <input type='text' size='25' maxlength='25' name='email' value='$users[email]'></td>
  38. </tr>
  39. <tr>
  40. <td align='right' width='25%'>Location</td>
  41. <td align='left'>
  42. <input size='25' name='location' value='$users[location]'></td>
  43. </tr>
  44. <tr>
  45. <td align='right' width='25%'>Age</td>
  46. <td align='left'>
  47. <input size='25' name='age' value='$users[age]'></td>
  48. </tr>
  49. <tr>
  50. <td align='center'></td>
  51. <td align='left'>
  52. <input type='submit' name='submit' value='Update'></td>
  53. </tr>
  54. </table>
  55. </form>
  56. ");
  57. if($_POST[submit])
  58. {
  59. $email = htmlspecialchars($_POST[email]);
  60. $age = htmlspecialchars($_POST[age]);
  61. $location = htmlspecialchars($_POST[location]);
  62. $level = htmlspecialchars($_POST[level]);
  63. echo ("Thank you $logged[username], $member's profile was updated!");
  64. $update = mysql_query(UPDATE `members` SET location = '$location', age = '$age', level = '$level', email = '$email' where username = '$member'");
  65. }
  66. break;
  67. }
  68. else
  69. {
  70. echo ("Sorry, but only Admins may view this page. Please go back!");
  71. }
  72. ?>


Try that one, just whipped it up now.
Posted on Thursday 31st May 2007 at 02:47 PM
MCP
MCP's Avatar
That one is still just a blank page.
Posted on Thursday 31st May 2007 at 07:37 PM
Diablosblizz
Diablosblizz's Avatar
PHP Code
  1. else
  2. {
  3. echo ("Sorry, but only Admins may view this page. Please go back!");


Replace that with this:

PHP Code
  1. if($logged[username] && $logged[level] == !6)
  2. {
  3. echo ("Sorry, but only Admins may view this page. Please go back!");


The ! makes sure that the user isn't 6 so it can be anything else.

Not 100% sure if it works.
Posted on Thursday 31st May 2007 at 09:30 PM
SkillMaster
SkillMaster's Avatar
Tsk if you need help please post your code and we can find errors its the only way.
Posted on Thursday 31st May 2007 at 09:35 PM
MCP
MCP's Avatar
Here it is. My entire admin.php code

PHP Code
  1. <?php
  2. session_start();
  3. include "config.php";
  4. if($logged[username] && $logged[level] == 6)
  5. {
  6. switch($_GET[page])
  7. {
  8. default:
  9. $fetch = mysql_query("SELECT * FROM `members` ORDER BY username ASC");
  10. while($users = mysql_fetch_array($fetch))
  11. {
  12. echo ("<a href='?page=edit&member=$users[username]'>- $users[username]</a><br>");
  13. }
  14. break;
  15.  
  16. case 'edit':
  17. $member = $_GET[member];
  18. $user = mysql_query("SELECT * FROM `members` where username = '$member'");
  19. $users = mysql_fetch_array($user);
  20. echo ("
  21. <form method='POST'>
  22. <table width='100%'>
  23. <tr>
  24. <td align='right' width='25%'>
  25. User Level</td>
  26. <td align='left'>
  27. <select name='level'>
  28. <option value='2'>User</option>
  29. <option value='4'>Mod</option>
  30. <option value='6'>Admin</option>
  31. </select> </td>
  32. </tr>
  33. <tr>
  34. <td align='right' width='25%'>
  35. Email</td>
  36. <td align='left'>
  37. <input type='text' size='25' maxlength='25' name='email' value='$users[email]'></td>
  38. </tr>
  39. <tr>
  40. <td align='right' width='25%'>Location</td>
  41. <td align='left'>
  42. <input size='25' name='location' value='$users[location]'></td>
  43. </tr>
  44. <tr>
  45. <td align='right' width='25%'>Age</td>
  46. <td align='left'>
  47. <input size='25' name='age' value='$users[age]'></td>
  48. </tr>
  49. <tr>
  50. <td align='center'></td>
  51. <td align='left'>
  52. <input type='submit' name='submit' value='Update'></td>
  53. </tr>
  54. </table>
  55. </form>
  56. ");
  57. if($_POST[submit])
  58. {
  59. $email = htmlspecialchars($_POST[email]);
  60. $age = htmlspecialchars($_POST[age]);
  61. $location = htmlspecialchars($_POST[location]);
  62. $level = htmlspecialchars($_POST[level]);
  63. echo ("Thank you $logged[username], $member's profile was updated!");
  64. $update = mysql_query(UPDATE `members` SET location = '$location', age = '$age', level = '$level', email = '$email' where username = '$member'");
  65. }
  66. break;
  67. }
  68. if($logged[username] && $logged[level] == !6)
  69. {
  70. echo ("Sorry, but only Admins may view this page. Please go back!");
  71. }
  72. ?>
Posted on Friday 1st June 2007 at 11:09 PM
SkillMaster
SkillMaster's Avatar
PHP Code
  1. <?php
  2. session_start();
  3. include "config.php";
  4. if($logged[username] && $logged[level] == 6)
  5. {
  6. switch($_GET[page])
  7. {
  8. default:
  9. $fetch = mysql_query("SELECT * FROM `members` ORDER BY username ASC");
  10. while($users = mysql_fetch_array($fetch))
  11. {
  12. echo ("<a href='?page=edit&member=$users[username]'>- $users[username]</a><br>");
  13. }
  14. break;
  15.  
  16. case 'edit':
  17. $member = $_GET[member];
  18. $user = mysql_query("SELECT * FROM `members` where username = '$member'");
  19. $users = mysql_fetch_array($user);
  20. echo ("
  21. <form method='POST'>
  22. <table width='100%'>
  23. <tr>
  24. <td align='right' width='25%'>
  25. User Level</td>
  26. <td align='left'>
  27. <select name='level'>
  28. <option value='2'>User</option>
  29. <option value='4'>Mod</option>
  30. <option value='6'>Admin</option>
  31. </select> </td>
  32. </tr>
  33. <tr>
  34. <td align='right' width='25%'>
  35. Email</td>
  36. <td align='left'>
  37. <input type='text' size='25' maxlength='25' name='email' value='$users[email]'></td>
  38. </tr>
  39. <tr>
  40. <td align='right' width='25%'>Location</td>
  41. <td align='left'>
  42. <input size='25' name='location' value='$users[location]'></td>
  43. </tr>
  44. <tr>
  45. <td align='right' width='25%'>Age</td>
  46. <td align='left'>
  47. <input size='25' name='age' value='$users[age]'></td>
  48. </tr>
  49. <tr>
  50. <td align='center'></td>
  51. <td align='left'>
  52. <input type='hidden' value='$member' name='member'>
  53. <input type='submit' name='submit' value='Update'></td>
  54. </tr>
  55. </table>
  56. </form>
  57. ");
  58. if($_POST[submit])
  59. {
  60. $member = htmlspecialchars($_POST[member]);
  61. $email = htmlspecialchars($_POST[email]);
  62. $age = htmlspecialchars($_POST[age]);
  63. $location = htmlspecialchars($_POST[location]);
  64. $level = htmlspecialchars($_POST[level]);
  65. echo ("Thank you $logged[username], $members profile was updated!");
  66. $update = mysql_query(UPDATE `members` SET location = '$location', age = '$age', level = '$level', email = '$email' where username = '$member'");
  67. }
  68. break;
  69. }
  70. if($logged[username] && $logged[level] == !6)
  71. {
  72. echo ("Sorry, but only Admins may view this page. Please go back!");
  73. }
  74. ?>


Try that.
Posted on Saturday 2nd June 2007 at 12:40 AM
MCP
MCP's Avatar
Nope. Still a blank page.
Posted on Sunday 3rd June 2007 at 08:55 PM
SkillMaster
SkillMaster's Avatar
I can't see anything wrong, If anyone is able to examine over it and find the problem?
Posted on Sunday 3rd June 2007 at 08:56 PM
SkillMaster
SkillMaster's Avatar
As i posted it i found it. change $logged[level] to $logged[userlevel]

That should work.
Posted on Monday 4th June 2007 at 04:59 PM
MCP
MCP's Avatar
Ok I tried that. I ended up with another blank page. :(

This is the code for my admin.php
PHP Code
  1. <?
  2. session_start(); //allows session
  3. include "config.php"; // Includes the config
  4. if($logged[username] && $logged[userlevel] == 6)// Checks you are an admin
  5. {
  6. if($_GET[member])//gets the username
  7. {
  8. if (!$_POST[edit])//Checks if you are editing a user already
  9. {
  10. $user = mysql_query("SELECT * from members where username = '$_GET[member]'");// Selcts the right user from the database
  11. $users = mysql_fetch_array($user);
  12. echo "<form method='POST'>
  13. <table width='100%'>
  14. <tr>
  15. <td align='right' width='25%'>
  16. User Level</td>
  17. <td align='left'>
  18. <select name='level'>
  19. <option value='2'>User</option>
  20. <option value='4'> Mod </option>
  21. <option value='6'> Admin</option>
  22. </select> </td>
  23. </tr>
  24. <tr>
  25. <td align='right' width='25%'>
  26. Email</td>
  27. <td align='left'>
  28. <input type='text' size='25' maxlength='25' name='email'
  29. value='$users[email]'></td>
  30. </tr>
  31. <tr>
  32. <td align='right' width='25%'>Location</td>
  33. <td align='left'>
  34. <input size='25' name='location' value='$users[location]'></td>
  35. </tr>
  36. <tr>
  37. <td align='right' width='25%'>Age</td>
  38. <td align='left'>
  39. <input size='25' name='age' value='$users[age]'></td>
  40. </tr>
  41. <tr>
  42. <td align='center'></td>
  43. <td align='left'>
  44. <input type='submit' name='edit' value='Update'></td>
  45. </tr>
  46. </table>
  47. </form>
  48. "; // Displays the form
  49. }else{
  50. $email = htmlspecialchars($_POST[email]);//removes all HTML
  51. $age = htmlspecialchars($_POST[age]);//removes all HTML
  52. $location = htmlspecialchars($_POST[location]);//removes all HTML
  53. $level = htmlspecialchars($_POST[level]);//removes all HTML
  54. echo "Thank you $logged[username], $_GET[member]'s Profile was updated!"; // Shows the message of your choice (feel free to change it)
  55. $update = mysql_query("Update members set location = '$location', age = '$age', level = '$level', email = '$email' where username = '$_GET[member]'"); // updates the user
  56. }
  57. }else{
  58. $adminuser = mysql_query("Select * from members order by username asc"); //Makes a list of all the users in alphabeticle order!
  59. while($adminusers = mysql_fetch_array($adminuser))
  60. {
  61. echo "<a href='admin.php?member=$adminusers[username]'>$users[username]</a>"; //Displayes the links to edit the user.
  62. }
  63. }
  64. }else{
  65. //If someone is trying to get onto this page without being an admin then they wont get through!
  66. echo "Sorry, but only Admins may view this page. Please go back!";
  67. }
  68. ?>
Login or register to respond to this forum topic.