Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF Statements 1

Status
Not open for further replies.

JamesCliff

Programmer
Feb 16, 2005
106
GB
Hi all,

Ok.... i have a page with the following code (note: these are snippets of code from the page)

Code:
	if($_SESSION['password'] == $db_pass['password']) { 
		$logged_in = 1;
					
	$user_lev = $db_object->query("SELECT user_level FROM brisk_users WHERE username = '".$_SESSION['username']."'");
					
	} else {
		$logged_in = 0;
		unset($_SESSION['username']);
		unset($_SESSION['password']);
	}

As you can see this is where i get my $logged_in and $user_lev variable from. $user_lev is the important variable here as everything else works how its supposed to.

Further down the page i have this snipped of code:

Code:
if($logged_in == 1) {

?>
  <div align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif" color="4C4C4C">Welcome back <?php echo $_SESSION['username']; ?>, 
  you are logged in.&nbsp;&nbsp;&nbsp;</font></font><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="logout.php">**LOGOUT**</a></font></div>
<?php
}
else
{
...................
}

Now as you can see above if the $logged_in variable is set to 1 then the logged in text is displayed. This works fine, however im setting up a user level system.

Basiclly as you can see in the first snippet of code im getting the specific users user_level from the database. There is 2 values the users level can be; these are 0 (member with no privalages) and 1 (site mod / admin).

I want it so when a user with a 0 $user_lev value signs in they are greeted with the original logged in message thats within the second snippet of code. However when a user with a $user_lev of 1 signs in they are greeted with the same message as the normal members message except it has the word "ADMIN" at the end. Once i have achieved this i can customize it even more.

Ive tried using IF statements within the $logged_in ifstatment but they dont work as they should. Is there anyway i can achieve what im trying to do? Surely it dosnt require much more code, a couple of lines maybe, however im not experienced enough to do this correctly.

Any help greatly appriciated.

Thanks alot

Jim
 
Hehe :)

Thanks m8, however it hasnt cracked it. This time nothing was been displayed at all. The " as Admin" didnt come up for users with a user_level of 1. I really dont know why, im lost now.

However, i tried the code you gave me earlier on in the thread:

if($logged_in == 1) {
echo $user_lev."XX";
}

Im not getting an object this time for some reason. All i get is "XX".

What does this mean m8? Does the query need changing or the echo?

I appriciate the help m8, i really do. If you have thought of everything you know and dont know what else it could be then dont worry about it. Ill have to take the user_level out of the login system if the worst comes to the worst.

However if you know of anything else at all it could be, tell me m8 hehe.

Appriciate it.

Thanks alot

Jim
 
OK. Let's try again. :)
After this line:
$row = $user_lev_rs->fetchRow();
Add:
echo "<pre>"; print_r($row); echo "</pre>";

And let me know what the output is.

Thank you.
 
hmmm very interesting m8.

I did what you said and then logged in as jim11 who has a user_level as 1 (admin). I then got the following:

Array
(
[user_level] => 1
)

I then logged in as chloecliff who has a user_level as 0 (normal user). I then got the following:

Array
(
[user_level] => 0
)


Does this mean the query is working, but the echo isnt?

Thanks
 
Yup. Cool.
We are there.

$row = $user_lev_rs->fetchRow();
$user_lev = $row["user_level"];

Now we solved the problem.
 
Yes m8!!!

It is sorted, your right! Thanks so so so so much,

I appriciate all your help totally! Finally its working lol, i can get building an admin link and make it secure.

Seriously, thanks so much for all the help, i really appriciate it.

Ive gien you a star :)

Thanks again

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top