freemancomputer Posted March 31, 2011 Share Posted March 31, 2011 I am attempting to have some links show up on my page only if a user is an admin. The way I have the user data base is user name password and rank. rank is a 1 or 2, 2 for admin. This is what I have right now as a test bed, I think the rank variable is not being passed properly but I'm not sure. Thanks in advance. This is what i have for the log in page <?php //connection stuff $sql="SELECT * FROM user WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); $rank=mysql_num_rows('rank'); if($count==1){ session_start(); $_SESSION['login'] = "1"; $_SESSION['rank'] = $rank; header ("Location:index.php"); } else { $errorMessage = "Invalid Login"; session_start(); $_SESSION['login'] = ''; } ?> This is the header that will be on every page to keep the session. <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); ?> <?php session_start(); if(!$_SESSION['login']){ $_SESSION['rank']; header("location:login.php"); } ?> <?php $rank=$_SESSION['rank']; ?> And this is what I have to show the link. <?php if($rank<=2){ ?> <tr> <td><span class="nav"><a href="link">link</a></span><br /></td> </tr> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/232249-user-privileges/ Share on other sites More sharing options...
Skewled Posted March 31, 2011 Share Posted March 31, 2011 $rank=mysql_num_rows('rank'); That's where your issue is. perhaps: $row = mysql_fetch_assoc($result); $rank = $row['rank']; EDIT: if($rank<=2){ From what you've stated then any user below admin rank will see this link. if you want admin only then: if($rank == 2) { Quote Link to comment https://forums.phpfreaks.com/topic/232249-user-privileges/#findComment-1194767 Share on other sites More sharing options...
freemancomputer Posted March 31, 2011 Author Share Posted March 31, 2011 Thank you that worked just right. Quote Link to comment https://forums.phpfreaks.com/topic/232249-user-privileges/#findComment-1194777 Share on other sites More sharing options...
Skewled Posted March 31, 2011 Share Posted March 31, 2011 Your most welcome! Quote Link to comment https://forums.phpfreaks.com/topic/232249-user-privileges/#findComment-1194789 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.