PDA

View Full Version : [php]Little bit of help! Why doesnt this work!



Fehm
05-04-2009, 08:03 PM
Hey!
So this is the third time ive come for help in 2 days and i feel bad :L So im more than understanding if people dont want to help me out!

Ive got this code:

<?
session_start();
include ("config.php");
$username = $_SESSION['username'];
$logged = mysql_query("SELECT * FROM `users` WHERE `username`='$username'");
$logged = mysql_fetch_array($logged);
?>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<?
if($logged["rank"] != "1") {
// not an admin.
exit("You need to be an administrator to view this feature"); // you can redirect to an error page, include something here, doesn't matter, just exit.
}

// aha.. they are an admin.. show the content.

include ("menus/anav.php")

?>

Dentafrice helped me with some of it but i went on to play around alot with it and see what i could get out of it!!

Now it doesnt work for some reason and nothing appears when logged in as rank 1 or any other ranks....

Can anyone help me!! THANKS :)

Edited by ReviewDude (Forum Moderator): Identical threads merged.

Joshh
06-04-2009, 03:54 PM
Hey!
So this is the third time ive come for help in 2 days and i feel bad :L So im more than understanding if people dont want to help me out!

Ive got this code:

<?
session_start();
include ("config.php");
$username = $_SESSION['username'];
$logged = mysql_query("SELECT * FROM `users` WHERE `username`='$username'");
$logged = mysql_fetch_array($logged);
?>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<?
if($logged["rank"] != "1") {
// not an admin.
exit("You need to be an administrator to view this feature"); // you can redirect to an error page, include something here, doesn't matter, just exit.
}

// aha.. they are an admin.. show the content.

include ("menus/anav.php")

?>Dentafrice helped me with some of it but i went on to play around alot with it and see what i could get out of it!!

Now it doesnt work for some reason and nothing appears when logged in as rank 1 or any other ranks....

Can anyone help me!! THANKS :)

Edited by ReviewDude (Forum Moderator): Identical threads merged.

I'm pretty sure it's for this reason, although I could be making myself look stupid.

If they are an admin then it shows the content but the content you're showing is

"include ("menus/anav.php")" but that doesn't show it it just includes it

I suggest echoing it for example:

echo ("contents of menus/anav.php here");

Fehm
06-04-2009, 04:11 PM
tried, didnt work :S
Lol :L DW ill fix :) thanks for your help anyway!

Dentafrice
06-04-2009, 04:17 PM
Try this and tell me what comes up:



<?
session_start();
include ("config.php");
$username = $_SESSION['username'];

echo "Username: {$username}<br />";

$logged = mysql_query("SELECT * FROM `users` WHERE `username`='$username'");
$logged = mysql_fetch_array($logged);

echo "<pre>";
print_r($logged);
echo "</pre>";
?>

Joshh
06-04-2009, 04:38 PM
I think it's because you're defining if they're not admin to not let them in but you're not defining if they're logged in, I would of used something like this, but it's probbably not like you need but it's worth a shot:


<?
session_start();
include ("config.php");
$username = $_SESSION['username'];
$logged = mysql_query("SELECT * FROM `users` WHERE `username`='$username'");
$logged = mysql_fetch_array($logged);
?>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<?
if($logged["rank"] != "1") {
// not an admin.
exit("You need to be an administrator to view this feature"); // you can redirect to an error page, include something here, doesn't matter, just exit.
}

else

{

if($logged["rank"] != "admin rank here") {
// is an admin.
exit("You're an admin!"); // you can redirect to an error page, include something here, doesn't matter, just exit.
}

echo ("the contents of menus/anav.php here")

}

?> then again probbably wrong again lol i'm just thinking through of what it could be. There's probbably an error in there, wasn't really paying attention when did it.

Dentafrice
06-04-2009, 04:49 PM
What is with the logic there? You're checking to see if they're not an admin, then you're checking to see if they are not an admin again..?

Joshh
06-04-2009, 08:13 PM
What is with the logic there? You're checking to see if they're not an admin, then you're checking to see if they are not an admin again..?

no because


if($logged["rank"] != "1") {
// not an admin.
exit("You need to be an administrator to view this feature"); // you can redirect to an error page, include something here, doesn't matter, just exit.
}

checks to see if they're not an admin, but it's not checking to see if they are an admin so I added one to check if they are admin, so if they are admin it displays the anav.php if theyre not it displays the "you're not an admin" message

Dentafrice
06-04-2009, 08:19 PM
no because



checks to see if they're not an admin, but it's not checking to see if they are an admin so I added one to check if they are admin, so if they are admin it displays the anav.php if theyre not it displays the "you're not an admin" message

*Removed*

This is your code..

This checks to see if the rank is not 1, which I believe is the administrator rank.

If rank is not 1 (admin rank) Then display the message. You don't need the else, it exits.. so you don't need to else it.



if($logged["rank"] != "1") {
// not an admin.
exit("You need to be an administrator to view this feature"); // you can redirect to an error page, include something here, doesn't matter, just exit.
}


Now why *Removed* are you doing the same thing?

If rank is not admin rank Then display "You are an admin!" *Removed* You're saying they are an admin when they are not. Plus.. if they are not an admin.. it's not even going to get to this section anyway.



if($logged["rank"] != "admin rank here") {
// is an admin.
exit("You're an admin!"); // you can redirect to an error page, include something here, doesn't matter, just exit.
}

echo ("the contents of menus/anav.php here")



*Removed*

Edited by ReviewDude (Forum Moderator): Please do not insult other forum members, or post rude comments.

Fehm
06-04-2009, 08:19 PM
SHOCK HORROR

dentafrices way worked :L Yours didnt xox

Joshh
06-04-2009, 08:21 PM
*Removed*

This is your code..

This checks to see if the rank is not 1, which I believe is the administrator rank.

If rank is not 1 (admin rank) Then display the message. You don't need the else, it exits.. so you don't need to else it.



if($logged["rank"] != "1") {
// not an admin.
exit("You need to be an administrator to view this feature"); // you can redirect to an error page, include something here, doesn't matter, just exit.
}
Now why *Removed* are you doing the same thing?

If rank is not admin rank Then display "You are an admin!" *Removed* You're saying they are an admin when they are not. Plus.. if they are not an admin.. it's not even going to get to this section anyway.



if($logged["rank"] != "admin rank here") {
// is an admin.
exit("You're an admin!"); // you can redirect to an error page, include something here, doesn't matter, just exit.
}

echo ("the contents of menus/anav.php here")

*Removed*

I see, I didn't think 1 was the administrator rank. And when I read it earlier I thought it said echo not exit sorry. :P

Dentafrice
06-04-2009, 08:23 PM
I see, I didn't think 1 was the administrator rank.
Well he indicated that when he posted it, that if it wasn't 1 then it wasn't an admin.

Joshh
06-04-2009, 08:24 PM
Well he indicated that when he posted it, that if it wasn't 1 then it wasn't an admin.

Yeah I obviously didn't read it propperly because when I read it earlier I also thought it said echo and not exit, just me not reading propperly. :P

Fehm
07-04-2009, 09:13 AM
Yeah I obviously didn't read it propperly because when I read it earlier I also thought it said echo and not exit, just me not reading propperly. :P

Lol so read it properly next time before you give advice ;) And no need to argue people ive fixed it now :) THanks alot to everyone :P

Dentafrice
07-04-2009, 01:18 PM
Lol so read it properly next time before you give advice ;) And no need to argue people ive fixed it now :) THanks alot to everyone :P
Uh oh, you better not say anything with curse words in it to him, you might get an infraction!

Want to hide these adverts? Register an account for free!