Question:

Need help with this php code?

by  |  earlier

0 LIKES UnLike

what i am trying to do with this code is make the echo only appear if the user has a user level of 1, 2 or 3 if they have any other user level then nothing appears. Level 1 is admin level 2 is moderator and level 3 is help desk operator. here is the code;

<?php

logincheck();

$username=$_SESSION['username'];

{

if($info->userlevel=='1')

if($info->userlevel=='2')

if($info->userlevel=='3')

echo "

<tr>

<td bgcolor='#000000'><img src='images/arrow.gif'> <a href=\"staffcentre.php\" target=\"main\"><b>Staff Centre</a></td>

<tr>";

}

?>

thanks for any help

 Tags:

   Report

2 ANSWERS


  1. You would need to complete some If checks for that, there is a pretty good Tutorial explaining how to work with If Statements at Brugbart.

    http://www.brugbart.com/Tutorials/9/ - If Then, Else, ElseIf

    But note, you should not use deprecated attributes such as bgcolor, and you should not use tables for layout. Its much easier to deal with CSS based layouts.

    Example:

    -----StartCode-----

    &lt;?php

    $U_level = 1;

    if ($U_level == &#039;1&#039;) {

      echo &#039;You are level 1&#039;;

    } ElseIf ($U_level == &#039;2&#039;) {

      echo &#039;You are level 2&#039;;

    } ElseIf ($U_level == &#039;3&#039;) {

      echo &#039;You are level 3&#039;;

    } Else {

      echo &#039;you are level 0&#039;;

    }

    ?&gt;

    -----CodeEnd-----

    In your case it would be something like below:

    -----StartCode-----

    function logincheck() { // StartFunc

    global $info;

    if ($info == &#039;1&#039; || &#039;2&#039; || &#039;3&#039;) {

    echo &#039;&lt;tr&gt;&lt;td style=&quot;background: #000000;&quot;&gt;&lt;img src=&quot;images/arrow.gif&quot;&gt; &lt;a href=&quot;\staffcentre.php&quot;&gt;Staff Centre&lt;/a&gt;&lt;/td&gt;&lt;tr&gt;&#039;;

    } Else {

      // Doing nothing

    }

    } // EndFunc

    -----StartCode-----

    You need to declare the $info variable as global, before you can use it in your function.

    The content of $info would be output from the database, containing the level of the specific user. Of cause you will need to combine the above with your real logged in check.



    See also:

    http://php.net/if - If


  2. &lt;?php

    logincheck();

    $username=$_SESSION[&#039;username&#039;];

    if($info-&gt;userlevel== &#039;1&#039; || &#039;2&#039; || &#039;3&#039;){

    echo &quot;

    &lt;tr&gt;

    &lt;td bgcolor=&#039;#000000&#039;&gt;&lt;img src=&#039;images/arrow.gif&#039;&gt; &lt;a href=\&quot;staffcentre.php\&quot; target=\&quot;main\&quot;&gt;&lt;b&gt;Staff Centre&lt;/a&gt;&lt;/td&gt;

    &lt;tr&gt;&quot;;

    }

    ?&gt;

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.