0

Hi,

I'm trying to just grab a small column of data from a Database and return it.

This is a function called getAccessLevel(), it returns the Access level which is an integer.
There is a table called users in the DB and the column access holds either 0, 1, or 2 to determine what users access level is. I'm trying to get the access level of a user that has the matching ID.

This is what I have thus far (**** to cover certain privacy things):

include("functions/global_functions.php");
$link = connectDatabase();
$mydb = mysql_select_db($dbname)or die("Can't select");
$userID = getID();
$query = "SELECT * FROM $tbl_name WHERE 'id'='$userID'";
$result = mysql_query($query);

$row = mysql_fetch_assoc($result);

mysql_free_result($result);

return $row['access'];

My function methods have worked in other pages, but I just haven't done that query or row fetch to isolate a single row before...I don't understand why this doesn't work.

Any help would be terrific, if you need more explanation just let me know! Thanks.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by jeeter19
1

change return to echo and see if anything is displayed. Your code looks OK, but is getID() grabbing an id in the first place?

you could do

echo $query;

to see if your query is correct - if you get a sensible output, paste it into myphpadmin (SQL tab) to see if a record is returned.

0

Maybe it's messing up at getID(). I'll look into that and also change that statement to echo.

Thanks.

0

Fixed it! I was getting the userID from a session cookie, but I had the username being saved in this instead of an ID. So it was trying to compare equivalency of an integer to a string.

Thank you for the quick reply, helped me out a lot.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.