Ell20 Posted October 15, 2007 Share Posted October 15, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/ Share on other sites More sharing options...
darkfreaks Posted October 15, 2007 Share Posted October 15, 2007 <?php $sql = "SELECT * FROM 'users' WHERE member_type=$member_type"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370191 Share on other sites More sharing options...
Ell20 Posted October 15, 2007 Author Share Posted October 15, 2007 Thanks for the help but it dosent seem to have solved the problem, still not menu or test message appearing. Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370192 Share on other sites More sharing options...
darkfreaks Posted October 15, 2007 Share Posted October 15, 2007 <?php $result = @mysql_query($sql) or die .mysql_error(); /// will throw out an error ?> Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370195 Share on other sites More sharing options...
Ell20 Posted October 15, 2007 Author Share Posted October 15, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370197 Share on other sites More sharing options...
darkfreaks Posted October 15, 2007 Share Posted October 15, 2007 <?php $sql = "SELECT * FROM users WHERE member_type=$member_type"; /// removed single quotes ?> Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370200 Share on other sites More sharing options...
Ell20 Posted October 15, 2007 Author Share Posted October 15, 2007 Getting there.....I think: 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 '' at line 1 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370201 Share on other sites More sharing options...
darkfreaks Posted October 15, 2007 Share Posted October 15, 2007 <?php $sql = 'SELECT * FROM users WHERE member_type='.$member_type.''; ///escaped it in single quotes and dots ?> Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370203 Share on other sites More sharing options...
Ell20 Posted October 15, 2007 Author Share Posted October 15, 2007 Hmm...made the suggested changes: If log in as Admin: "Unknown column 'Admin' in 'where clause'" If log in as Member: Unknown column 'Member' in 'where clause' Cheers Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370204 Share on other sites More sharing options...
darkfreaks Posted October 15, 2007 Share Posted October 15, 2007 is the member type stored in the database? if not that could bewhy Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370206 Share on other sites More sharing options...
Ell20 Posted October 15, 2007 Author Share Posted October 15, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370210 Share on other sites More sharing options...
darkfreaks Posted October 15, 2007 Share Posted October 15, 2007 i dont see how it could be undefined if it is fetching admin and user from the db? and going through the statement correctly Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370211 Share on other sites More sharing options...
trq Posted October 15, 2007 Share Posted October 15, 2007 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370212 Share on other sites More sharing options...
Ell20 Posted October 15, 2007 Author Share Posted October 15, 2007 Excellent working - Cheers Thank you both for your help, its appreciated Elliot Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370213 Share on other sites More sharing options...
trq Posted October 15, 2007 Share Posted October 15, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73373-solved-not-sure-whats-wrong-with-this-code/#findComment-370217 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.