trying to make an admin only page but I have a big issue

[php]
$getAdmin = mysql_query(“SELECT * FROM Members WHERE Username=’”.$User."’") or die(mysql_error());
$gA = mysql_fetch_object($getAdmin) or die(mysql_error());
if($gA->Rank==‘4’) {
echo ‘Admin’;
}
else {
echo “”’;
}
?>
[/php]

The problem is, if someone isn’t an admin the page just blanks out for some reason. But, if someone is an admin the site remains the same for them. I don’t know what’s wrong.

[php]

Home | Members | Forum | Blog <?php $getAdmin = mysql_query("SELECT * FROM Members WHERE Username='".$User."'") or die(mysql_error()); $gA = mysql_fetch_object($getAdmin) or die(mysql_error()); if($gA->Rank=='4') { } else { echo ""; } ?>
[/php]

there it is, I mean I want it in the navbar if you’re an admin, but if not I don’t want it there.

Please use this:
[php]

Home | Members | Forum | Blog <?php $getAdmin = mysql_query("SELECT * FROM phphelp_Members WHERE Username='".$User."'") or die(mysql_error()); $gA = mysql_fetch_object($getAdmin) or die(mysql_error()); if($gA->Rank=='4') { echo '| Admin'; } else { echo ""; } ?>
</center [/php] it works for me.

if user is admin 5 navigation will appear if user is not not admin only 4 navigation bar appear.

is that what you want?

I’m not sure what you meant, but it sounded like you were confused why it would be blank if they weren’t an admin. Here is what is glaring at me.

[php]else {
echo “”’;
}[/php]

Basically, this is saying that if their rank is NOT 4, it will show that echo. That echo is just a blank space.

If you want, you can add something simple like this.

[php]else {
echo “You don’t have the correct rank to view this. Redirecting in 3 seconds.”;
header(‘Refresh: 3; http://example.com’);
}[/php]

This just makes it to them saying that they aren’t the right rank, and will redirect in 3 seconds. I’m not an expert, and I might have misunderstood your question. If I did, sorry.

What I mean, is if the user < 4 everything on the page goes away, and the navbar removes the Alert or banner.

so okay if user is admin display the navBar , if user is not admin display nothing

this should do it

[php]

<?php $getAdmin = mysql_query("SELECT * FROM phphelp_Members WHERE Username='".$User."'") or die(mysql_error()); $gA = mysql_fetch_object($getAdmin) or die(mysql_error()); if($gA->Rank=='4') { echo "
Home | Members | Forum | Blog | Admin
"; } else { echo "Bro!! you are not an admin."; } ?>

[/php]

I don’t think that will work. I want the navbar to display for ALL users not just admins.

Well i give up on guessing
I do not understand what you want

So, basically what I want is

home | people | forum | blog | admin (if you’re an Admin)

home | people | forum | blog (if not an admin)

But it glitches, if you only see navbar. Everything else on the page just goes away and it doesn’t function.

if you look at my first post on this thread that is exactly what it does

when i try with an admin user i see home | people | forum | blog | admin

if not admin i see

home | people | forum | blog

are you you tried my code?

so what i mean is that admin navigation bar will only show if an admin is logged in

if that is what you want try out the codes i post on my first post

This is what it looks like when it works.

This is what it looks like when you signout, or aren’t an Admin

I created a table on my localhost specifically to test your codes and everything works just fine
the only thing i dont have is red color and design fancy looking that you have

when an user is admin
http://wilson382.info/admin.png

when user is not admin
http://wilson382.info/notadmin.png

[php]

<?php if ($User) { echo '
Welcome, '.$User.' Logout
'; } else { echo 'Welcome, Guest'; } ?>
Home | Members | Forum | Blog <?php $getAdmin = mysql_query("SELECT * FROM Members WHERE Username='".$User."'") or die(mysql_error()); $gA = mysql_fetch_object($getAdmin) or die(mysql_error()); if($gA->Rank=='4') { echo '| Admin'; } else { echo ""; } ?>
[/php]

Is it maybe that code where it says $User ?


[php]

Home | Members | Forum | Blog <?php

//since i dont have the login script m using a variable to specify users

$User = “wilson382”; //wilson382 has Rank 3

include(“connect_db.php”);

$getAdmin = mysql_query(“SELECT * FROM phphelp_Members WHERE Username=’”.$User."’") or die(mysql_error());
$gA = mysql_fetch_object($getAdmin) or die(mysql_error());
if($gA->Rank==‘4’) {
echo ‘|
Admin’;
}
else {
echo “”;
}
echo “

”;

if ($User) {
echo ’


Welcome, ‘.$User.’ Logout
'; }
else {
echo ‘Welcome, Guest’;
}
?>

[/php]

you should see it like in the image if you use the code above

doesn’t work, I honestly have no clue what’s wrong. I’ll just make a box with the link in it. Thanks for trying to help. If you know a script for that and you can help, thankyou. But that script doesn’t work.

the problem might be the variable $User not getting a value
let me help you thru teamviewer

.$User. stands for Username. So if I put $User = “name here” it will always say “name here”, I’m kinda newbie so I’m guessing I need to change the value .$User.

I can help you via teamviewer if you want

sent you a pm.

Sponsor our Newsletter | Privacy Policy | Terms of Service