Jump to content

Archived

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

almightyegg

showing other members profile

Recommended Posts

Don't call your variable $GET as it's too much like $_GET which is a predefined variable in php.

I'll post a simple bit of code for you to just see if it works, then complicate it and fit the other bits around it.  I've taken this nearly all from your code so it looks familiar to you.

[code]
<?php
// Connect to the database
include 'database.php';

// Query the database and assign the results to a variable
$view = "SELECT * FROM users WHERE id = '{$_GET['id']}' LIMIT 1";
$view2 = mysql_query($view) or die("Couldn't execute $sql:\n\n" . mysql_error());
$view3 = mysql_fetch_assoc($view2) or die("Couldn't fetch the results:" . mysql_error());
$user = $view3['username'];

$admin_ids = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

foreach ($admin_ids as $id){
  if ($view3['id'] == $id){
      $admin = "y";
  }
}

if ($admin == "y"){
  echo "{$view3['username']} is an administrator\n";
}
else {
  echo "{$view3['username']} is not an administrator\n";
}
?>
[/code]

Call this code something like testforadmin.php and make sure you pass it a value like this testforadmin.php?id=3

Post any errors that you get here.

Regards
Huggie

Share this post


Link to post
Share on other sites
thanks it worked perfectly, have started to tweak it now with other column values etc...
thanks again  ;D

Share this post


Link to post
Share on other sites
OK, well I'm glad that it worked.  You could reduce the overhead even more by including a 'role' column in your database that designates whether the user is 'admin' or not...

This way you can do away with the $admin_ids array and use the value from the database to check if their admin or not.  Something like this...

[code]<?php
if ($view3['role'] == "admin"){
  echo "{$view3['username']} is an administrator\n";
}
else {
  echo "{$view3['username']} is not an administrator\n";
}
?>[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites
yes i may do that, i have that column already, but i had it when i couldn't even do
[code=php:0]echo "Hello World!";[/code] :D

Share this post


Link to post
Share on other sites

×

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.