Jump to content

[SOLVED] Php if/elseif


Recommended Posts

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

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

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

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

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

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.