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
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
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
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
Share on other sites

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.