papillonstudios Posted June 7, 2009 Share Posted June 7, 2009 ok i have a piece of code that is supposed to check for user and guest. and it does but now i want it to check for admin also. and if admin display both user and admin stuff, but of course it not heres my code <?php if ($uId) { if ($uCan) echo "<img src=\"i/user_go.png\">Hey! <STRONG>$uName</STRONG>"; // helo member! echo '<p>'; echo "<a href=\"index.php?action=editprofile\">Edit Profile</a> <br>"; echo "<a href=\"index.php?action=memberlist\">View Members</a> <br>"; echo "<a href=\"index.php?action=logout\">Logout</a> <br>"; echo '</p>'; echo "<br />"; } elseif ($uCan['admin']) { echo '<br />'; echo '<p><a href="index.php?action=admin"><strong>Admin</strong></a></p>'; } else { // if this isn't a member then echo "<img src=\"i/user_go.png\">Welcome, <STRONG>$uName</STRONG>!"; echo '<p>'; echo "<br>"; echo "<a href=\"index.php?action=login\">Login</a>"; echo "/"; echo "<a href=\"index.php?action=register\">Sign up</a>"; echo '</p>'; } echo "<BR>"; //break echo "<BR>"; // break ?> Link to comment https://forums.phpfreaks.com/topic/161244-solved-php-ifelseif/ Share on other sites More sharing options...
XaeroDegreaz Posted June 7, 2009 Share Posted June 7, 2009 Are you sure that $uCan is an array? Link to comment https://forums.phpfreaks.com/topic/161244-solved-php-ifelseif/#findComment-850811 Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 Remove else in the elseif. Just leave it as if. Link to comment https://forums.phpfreaks.com/topic/161244-solved-php-ifelseif/#findComment-850812 Share on other sites More sharing options...
papillonstudios Posted June 7, 2009 Author Share Posted June 7, 2009 for the first reply $permquery1 = mysql_query("SELECT * FROM `permissions` WHERE mg_name = '$uMembergroup' "); $uCan = mysql_fetch_assoc($permquery1); and for the second if i leave just an if, when a user logs in it displays the user and guest stuff Link to comment https://forums.phpfreaks.com/topic/161244-solved-php-ifelseif/#findComment-850821 Share on other sites More sharing options...
XaeroDegreaz Posted June 7, 2009 Share Posted June 7, 2009 Here is what I came up with. <?php if ($uId) { if ($uCan) { echo "<img src=\"i/user_go.png\">Hey! <STRONG>$uName</STRONG>"; // helo member! echo '<p>'; echo "<a href=\"index.php?action=editprofile\">Edit Profile</a> <br>"; echo "<a href=\"index.php?action=memberlist\">View Members</a> <br>"; echo "<a href=\"index.php?action=logout\">Logout</a> <br>"; echo '</p>'; echo "<br />"; //# This needs its own if statement... if ($uCan['admin']) { echo '<br />'; echo '<p><a href="index.php?action=admin"><strong>Admin</strong></a></p>'; } //###### } else { // if this isn't a member then echo "<img src=\"i/user_go.png\">Welcome, <STRONG>$uName</STRONG>!"; echo '<p>'; echo "<br>"; echo "<a href=\"index.php?action=login\">Login</a>"; echo "/"; echo "<a href=\"index.php?action=register\">Sign up</a>"; echo '</p>'; } echo "<BR>"; //break echo "<BR>"; // break ?> Link to comment https://forums.phpfreaks.com/topic/161244-solved-php-ifelseif/#findComment-850826 Share on other sites More sharing options...
papillonstudios Posted June 7, 2009 Author Share Posted June 7, 2009 nope the sidebar just disappears Link to comment https://forums.phpfreaks.com/topic/161244-solved-php-ifelseif/#findComment-850831 Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 and for the second if i leave just an if, when a user logs in it displays the user and guest stuff Mind showing me what you did there? It should look like this - <?php if ($uId) { if ($uCan) { echo "<img src=\"i/user_go.png\">Hey! <STRONG>$uName</STRONG>"; // helo member! echo '<p>'; echo "<a href=\"index.php?action=editprofile\">Edit Profile</a> <br>"; echo "<a href=\"index.php?action=memberlist\">View Members</a> <br>"; echo "<a href=\"index.php?action=logout\">Logout</a> <br>"; echo '</p>'; echo "<br />"; if ($uCan['admin']) { echo '<br />'; echo '<p><a href="index.php?action=admin"><strong>Admin</strong></a></p>'; } } } else { // if this isn't a member then echo "<img src=\"i/user_go.png\">Welcome, <STRONG>$uName</STRONG>!"; echo '<p>'; echo "<br>"; echo "<a href=\"index.php?action=login\">Login</a>"; echo "/"; echo "<a href=\"index.php?action=register\">Sign up</a>"; echo '</p>'; } echo "<BR>"; //break echo "<BR>"; // break Link to comment https://forums.phpfreaks.com/topic/161244-solved-php-ifelseif/#findComment-850833 Share on other sites More sharing options...
papillonstudios Posted June 7, 2009 Author Share Posted June 7, 2009 ok i got it to display the admin but when i login under an user account it doesn't diplays anything <?php if ($uId) { if ($uCan['user']) { echo "<img src=\"i/user_go.png\">Hey! <STRONG>$uName</STRONG>"; // helo member! echo '<p>'; echo "<a href=\"index.php?action=editprofile\">Edit Profile</a> <br>"; echo "<a href=\"index.php?action=memberlist\">View Members</a> <br>"; echo "<a href=\"index.php?action=logout\">Logout</a> <br>"; echo '</p>'; echo "<br />"; //# This needs its own if statement... } if ($uCan['admin']) { echo "<img src=\"i/user_go.png\">Hey! <STRONG>$uName</STRONG>"; // helo member! echo '<p>'; echo "<a href=\"index.php?action=editprofile\">Edit Profile</a> <br>"; echo "<a href=\"index.php?action=memberlist\">View Members</a> <br>"; echo "<a href=\"index.php?action=logout\">Logout</a> <br>"; echo '</p>'; echo "<br />"; echo '<br />'; echo '<p><a href="index.php?action=admin"><strong>Admin</strong></a></p>'; } } else { // if this isn't a member then echo "<img src=\"i/user_go.png\">Welcome, <STRONG>$uName</STRONG>!"; echo '<p>'; echo "<br>"; echo "<a href=\"index.php?action=login\">Login</a>"; echo "/"; echo "<a href=\"index.php?action=register\">Sign up</a>"; echo '</p>'; } echo "<BR>"; //break echo "<BR>"; // break ?> Link to comment https://forums.phpfreaks.com/topic/161244-solved-php-ifelseif/#findComment-850835 Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 Before if ($uId) { , put this - var_dump($uId, $uCan); . What does that print out? Link to comment https://forums.phpfreaks.com/topic/161244-solved-php-ifelseif/#findComment-850837 Share on other sites More sharing options...
papillonstudios Posted June 7, 2009 Author Share Posted June 7, 2009 string(1) "2" array(6) { ["mg_id"]=> string(1) "1" ["mg_name"]=> string(4) "user" ["editprofile"]=> string(1) "1" ["viewprofile"]=> string(1) "1" ["admin"]=> string(1) "0" ["moderate"]=> string(1) "0" } Link to comment https://forums.phpfreaks.com/topic/161244-solved-php-ifelseif/#findComment-850841 Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 Wait timeout, did you try the code I posted? Link to comment https://forums.phpfreaks.com/topic/161244-solved-php-ifelseif/#findComment-850843 Share on other sites More sharing options...
papillonstudios Posted June 7, 2009 Author Share Posted June 7, 2009 ya that what it gave me Link to comment https://forums.phpfreaks.com/topic/161244-solved-php-ifelseif/#findComment-850846 Share on other sites More sharing options...
papillonstudios Posted June 7, 2009 Author Share Posted June 7, 2009 oh sorry man didnt see that post and it works thanks problem solved Link to comment https://forums.phpfreaks.com/topic/161244-solved-php-ifelseif/#findComment-850847 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.