Jump to content

[SOLVED] Not sure whats wrong with this code


Ell20

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 [email protected] 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.

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.