Jump to content

Recommended Posts

Hey, Im attempting to make a special menu for the Admin of the site which only they can see. Im getting no errors but it dosent seem to be working.

 

//Function
function getUserInfo($user_id,$fields){
$sql="select $fields from `users` where  user_id='$user_id' ";
$query=mysql_query($sql);
$rows=mysql_num_rows($query);
if($rows==0){return;}
$rs=mysql_fetch_assoc($query);
return $rs;
}

//Code
<?php
require_once ('../mysql_connect.php');
include_once ('includes/functions.php');

$user_id = $_SESSION['user_id'];
$userinfo=getUserInfo($user_id, '*');
$member_type = $userinfo['member_type'];
$sql = "SELECT * FROM users WHERE member_type='$member_type'";
$result = @mysql_query($sql);
if($result['member_type'] == "Admin"){
?>
Message Will Appear If Admin
<a href="admin.php">Admin Test</a><br />
<? }
?>

 

Any help would be appreciated

 

Cheers

I changed your line slightly and got this error:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''users' WHERE member_type=Admin' at line 1

 

Cheers

Amazingly enough yeah:

 

user_id  club_id  member_type  username    first_name  last_name          email                    password              registration_date

1       1 Admin           Ell20     Elliot       Reeve ell@reeve.plus.com 37e455b94f62fb0d 2007-10-13

 

Cheers

Which part isn't working? The part in the function or the other? In the other, you never fetch any data from your resultset. Try...

 

<?php

 require_once ('../mysql_connect.php');
 include_once ('includes/functions.php');

 $user_id = $_SESSION['user_id'];
 $userinfo = getUserInfo($user_id, '*');
 $member_type = $userinfo['member_type'];
 $sql = "SELECT * FROM users WHERE member_type='$member_type' LIMIT 1";
 if ($result = mysql_query($sql)) {
   if (mysql_num_rows($result)) {
     $row = mysql_fetch_assoc($result);
     if ($row['member_type'] == "Admin") {
       echo "Message Will Appear If Admin";
       echo "<a href=\"admin.php\">Admin Test</a><br />";
     }
   }
 } else {
   echo mysql_error();
 }

?>

Still, your code should be changed to this....

 

<?php

 require_once ('../mysql_connect.php');
 include_once ('includes/functions.php');

 $sql = "SELECT member_type FROM users WHERE user_id = '{$_SESSION['user_id']}' LIMIT 1";
 if ($result = mysql_query($sql)) {
   if (mysql_num_rows($result)) {
     $row = mysql_fetch_assoc($result);
     if ($row['member_type'] == "Admin") {
       echo "Message Will Appear If Admin";
       echo "<a href=\"admin.php\">Admin Test</a><br />";
     }
   }
 } else {
   echo mysql_error();
 }

?>

 

And remove that function at the top all together.

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.