Jump to content

Switch function not working for me.


Sileencer

Recommended Posts

This is my  file name    admin.php

 

<?

include("../include/session.php");

if(!$session->isAdmin()){
   header("Location: ../main.php");
}
else {


function main() {
global $database, $session;
echo "<html>
<title>admin</title>
<body>
<h1>admin</h1>";

adminmenu();

echo"<font size=\"5\" color=\"#ff0000\">
<b>::::::::::::::::::::::::::::::::::::::::::::</b></font>
<font size=\"4\">Logged in as <b> $session->username; </b></font><br><br>
Back to [<a href=\"../main.php\">Main Page</a>]<br><br>";

if($form->num_errors > 0){
   echo "<font size=\"4\" color=\"#ff0000\">"
       ."!*** Error with request, please fix</font><br><br>";
}

echo "</body></html>";

}


function adminmenu() {
global $database;

echo "<table align=\"center\"><tr><td>Menu</td></tr></table>";
echo "<table align=\"center\"><tr><td><a href=\"admin.php?op=displayUsers\">users</a></td><td><a href=\"admin.php?op=test\">test</a></td></tr></table>";

}




function displayUsers(){
   global $database, $session;
   echo "test";
   $q = "SELECT username,userlevel,email,timestamp "
       ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
   $result = $database->query($q);
   $num_rows = mysql_numrows($result);
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }   
   
   echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
   echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n";
   for($i=0; $i<$num_rows; $i++){
      $uname  = mysql_result($result,$i,"username");
      $ulevel = mysql_result($result,$i,"userlevel");
      $email  = mysql_result($result,$i,"email");
      $time   = mysql_result($result,$i,"timestamp");

      echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$time</td></tr>\n";
   }
   echo "</table><br>\n";
}


function displayBannedUsers(){
   global $database;
   $q = "SELECT username,timestamp "
       ."FROM ".TBL_BANNED_USERS." ORDER BY username";
   $result = $database->query($q);

   $num_rows = mysql_numrows($result);
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }
   echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
   echo "<tr><td>This a test <b>Username</b></td><td><b>Time Banned</b></td></tr>\n";
   for($i=0; $i<$num_rows; $i++){
      $uname = mysql_result($result,$i,"username");
      $time  = mysql_result($result,$i,"timestamp");

      echo "<tr><td>$uname</td><td>$time</td></tr>\n";
   }
   echo "</table><br>\n";
}



switch($op) {

case "test":
	echo "test";
	break;

case "adminmenu":
         adminmenu();
         break;
    
case "displayUsers":
         displayUsers();
         break;
    
case "displayBannedUsers":
         displayBannedUsers();
         break;

default:
	main();
	break;

}

}

 

 

if I have the following on address bar

 

admin.php?op=test

 

or anything else just like displayUsers

 

doesn't work  I always get the same output

 

Getting the output from  main();

 

 

I appreciate any help ty

Link to comment
https://forums.phpfreaks.com/topic/173396-switch-function-not-working-for-me/
Share on other sites

You're depending on register_globals being turned on, which is bad. But apparently it's turned off, and that's good.

 

To access the value of op in the query string, you use

 

$_GET['op']

So you can switch() on that, or store the value in $op before the switch().

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.