wtfsmd Posted January 17, 2007 Share Posted January 17, 2007 Hey guys, im trying to figure out why i can't get this to work :-\here is what i need help with: I am trying to make the session get the userrank for whom ever is logged in, regular people have the rank of 1, admins have the rank of 2. currently my userrank Session is not working most likely because of a error.i cut out most of the code, this is just the stuff i thought would be important.[code]<?php//start sessionsession_start();//include the database loginrequire 'login/db_connect.php'; //make a connection to the database $sql = "SELECT username, password, userrank FROM users WHERE username = '".$_POST['uname']."'"; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); // where $row is the record pulled from the database. $_SESSION['level'] = $row['userrank'];?>[/code]on the page that i want admin privileges on i have this:[code]<?php include('fetchnews.php'); print_r($_SESSION);//session user idif($_SESSION['level'] == "2") { include('test.php'); } else { }?>[/code]I have print_r($_SESSION), and what i get is this:[quote]Array ( [username] => Admin [password] => d159167596fd8ac07a8c9cf92150848d [level] => )[/quote]Here is a screenshot of my database table [url=http://tinypic.com/2z7mkie.png]http://tinypic.com/2z7mkie.png[/url]Any help would be appreciated, i most likely did this wrong lol. Link to comment https://forums.phpfreaks.com/topic/34514-session-permissions-giving-the-user-permission-when-they-log-in/ Share on other sites More sharing options...
linuxdream Posted January 17, 2007 Share Posted January 17, 2007 What's the output of a print_r($row) on your first page? Make sure the $row['userrank'] value is actually getting set right. Then you will know if it is either the MySQL query or the session that is bad.Brandon C. Link to comment https://forums.phpfreaks.com/topic/34514-session-permissions-giving-the-user-permission-when-they-log-in/#findComment-162614 Share on other sites More sharing options...
wtfsmd Posted January 17, 2007 Author Share Posted January 17, 2007 it does not even want to display $row, nothing shows up. Link to comment https://forums.phpfreaks.com/topic/34514-session-permissions-giving-the-user-permission-when-they-log-in/#findComment-162640 Share on other sites More sharing options...
wtfsmd Posted January 17, 2007 Author Share Posted January 17, 2007 Okay, i fixed it i took out[code]$row = mysql_fetch_array($result) or die(mysql_error());[/code]and i put in this further down the page[code]$result = mysql_query("SELECT userrank FROM users WHERE username = '".$_POST['uname']."'") or die(mysql_error()); $row = mysql_fetch_array( $result) or die (mysql_error());[/code] Link to comment https://forums.phpfreaks.com/topic/34514-session-permissions-giving-the-user-permission-when-they-log-in/#findComment-162646 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.