Jump to content

Help with query?


Perad

Recommended Posts

Right, i have an admin query.

[code]
global $dbc, $user_id, $uncaccess;
$adminaccess = 0;
$query = "SELECT user_id=$user_id FROM unc_user_group WHERE group_id=2;";
$result = mysql_query($query)or die(mysql_error());;
$row = (mysql_fetch_assoc ($result));
if (($row['user_id='.$user_id])==1) {
$uncaccess = 1;
echo '<a href="folder/admin.php">Admin Control Panel</a>';
} else {
$uncaccess = 0;
}[/code]

This is simply used to display a link to the admin panel.

The idea simply is to simply check against the forums user group to see if you fall into the admin category. The problem with this is that if you are in more than one group the test often fails.

For example.

My top admin account gets the following back from the query
1
0

My secondary admin account gets out
0
1

The query interprets the second user as not having admin privileges

$user_id simply gets the users id. This is then checked against the following table.

group_id  user_id  user_pending
1            -1 0


Could someone help me fix this query so that it always finds the number 1 no matter what order the numbers come out in.
Link to comment
Share on other sites

Unless I'm mistaken, that query will return a record for every row in the table. I'm assuming you just have two accounts in there at the moment. A better approach would be to query records where the user id is the one you are interested in where it exists in group 2. If any record is returned the user is an admin.
[code]<?php
global $dbc, $user_id, $uncaccess;

$adminaccess = 0;

$query = "SELECT * FROM unc_user_group WHERE group_id=2 AND user_id=".$user_id;
$result = mysql_query($query)or die(mysql_error());;

if (mysql_num_rows($result)>0) {
    $uncaccess = 1;
    echo '<a href="folder/admin.php">Admin Control Panel</a>';
} else {
    $uncaccess = 0;
}
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.