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
https://forums.phpfreaks.com/topic/32309-help-with-query/
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
https://forums.phpfreaks.com/topic/32309-help-with-query/#findComment-150070
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.