Jump to content

Recommended Posts

What do you want with the $level array?
Do you want it to loop through all it's elements and echo different things depending on the level? For that:

[code]foreach ($level as $l) {
   if ($l < 1) {
      echo "blah";  
   } elseif ($l >= 1) {
      echo " blah blah";
   }
}[/code]
Link to comment
https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44019
Share on other sites

sorry i gave a bad example/// i got a enum set from 0 to 5 on my database.. that determin the level of the user..

when the user agree to something it has to change from 0 to one and so on..

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]


<?php if($level == 0){?>
<tr>
<td colspan="3"><div align="center">This page contain adult content, and should only be view be people 18 or older.<br />
are you 18 or older?
<form method="post" action="<?php $_SERVER['PHP_SELF']?>" name="yf"><label>
<input type="submit" name="Submit" value="yes" />
</label>
</form>
by clicking yes, you agree to be 18 years of age or older.

<?php if(isset($_POST['Submit'])){
$query=mysql_query("UPDATE tra_users SET level='1' WHERE username='$username'")or die(mysql_error);
}?>

<?php
}elseif($level >= 1){
echo "blah"
}
?>

[/quote]
Link to comment
https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44033
Share on other sites

Well, I assume there's far more code than we're seeing - at least I assume so. There's no database connection and no way in which $level gets any value at the start of that code. If I read the logic right, the form submit is only checked when $level = 0 (otherwise, it always drops through to the else).
Link to comment
https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44168
Share on other sites

mm i didn't posted the whole code because is a big script , i jus tposted the part i know i'm having trouble with and $level gets it's value from $_session wich is passed on with every page.. everything is set up like is supossed to.. it's just tha tpart that i don't know how to make it work..
Link to comment
https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44174
Share on other sites

[!--quoteo(post=382563:date=Jun 11 2006, 05:41 PM:name=Richard181)--][div class=\'quotetop\']QUOTE(Richard181 @ Jun 11 2006, 05:41 PM) [snapback]382563[/snapback][/div][div class=\'quotemain\'][!--quotec--]
any one has a level system that can tell me how they got it to work ?
[/quote]

what for users!

[!--quoteo(post=382564:date=Jun 11 2006, 05:48 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Jun 11 2006, 05:48 PM) [snapback]382564[/snapback][/div][div class=\'quotemain\'][!--quotec--]
what for users!
[/quote]

Exsplain the consept of your script or post it ok,
i can not guess.

according with the help above there all correct
Link to comment
https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44332
Share on other sites

i want to make something like if a user has a level 5 he can do anything tot he site like a level 5 will be a admin, a level 1 would be someone that agree to somethings.. like that.. i made a enum('0','1','2','3','4'5')

and i passed the level in a $_session and tryed using if($level > 0 ){ do this}, but it doesn't work..
Link to comment
https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44335
Share on other sites

If $level is saved in a session ....

... then you need to retrieve the session value in any script where $level is used AND when you change $level you need to put it into the database AND update the value saved as the session variable - otherwise, you'll be looking at an outdated (and wrong) session value.

Link to comment
https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44338
Share on other sites

[!--quoteo(post=382567:date=Jun 11 2006, 05:54 PM:name=Richard181)--][div class=\'quotetop\']QUOTE(Richard181 @ Jun 11 2006, 05:54 PM) [snapback]382567[/snapback][/div][div class=\'quotemain\'][!--quotec--]
i want to make something like if a user has a level 5 he can do anything tot he site like a level 5 will be a admin, a level 1 would be someone that agree to somethings.. like that.. i made a enum('0','1','2','3','4'5')

and i passed the level in a $_session and tryed using if($level > 0 ){ do this}, but it doesn't work..
[/quote]

know any level that the user is the code will do as long as you set the do somethink.

example
[code]
<?
$query="select * from xxxxxx where id='$id'";
$result=mysql_query($query);

while ($record=mysql_fetch_assoc($result)){

if($record["level"] >=0) {

do somethink

}else{

echo "sorry not specified";
}
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44342
Share on other sites

How is $level being populated? Are you setting the variable like so:
$level = $_SESSION['level']

I think you'll be best of with a switch rather than if/elseif statement like so:
[code]<?php
session_start(); //make sure you have this line whenever you are dealing with sessions

$level = $_SESSION['level'];

switch($level)
{
    case 5:
        echo "level 5";
        break;
    case 4:
        echo "level 4";
        break;
    case 3:
        echo "level 3";
        break;
    case 2:
        echo "level 2";
        break;
    case 1:
        echo "level 1";
        break;
    case 0:
        echo "level 0";
        break;
    defualt:
        die("Unknown level script has been killed! level is:" . $level)
        break;
}[/code]
When you use that depending on the value of $level it should echo out the level, if $level is not set to 0,1,2,3,4 or 5 it'll kill the script and echo the value pf $level
Link to comment
https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44343
Share on other sites

To pass the level as session do this:
[code]<?php
session_start();

//put code here that gets the users level

$_SESSION['level'] = $level;

?>[/code]
Then when you want to retrieve the session make sure you have session_start on the page that checks the user level, see my post above.
Link to comment
https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44351
Share on other sites

What do you mean by refresh? Do want the browser to refesh the page? If so why?

To refresh the page in javascript you can do this:
[code]header("Refresh: 0; url=" . $_SERVER['PHP_SELF']);[/code]
provided that you dont have any output to the browser before you use that code.
Link to comment
https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44357
Share on other sites

no.. not the page... you know , when you change something that is passed by $_session it wont take effect until th euser close the current section and open a new one.. you know that right?

so what i need is a way for when the user change something that is used by a section to refresh that user section so the new information is in his current section.
Link to comment
https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44361
Share on other sites

Was you echoing out $level or $_SESSION['level']. If you was echoing out $level that will not update as holds the old value of level session. If you echo'd out $_SESSION['level'] that should echo out your new level that you set with the form.

Looks you have a bug in your script somewhere if the new session data isn't comming through.
Link to comment
https://forums.phpfreaks.com/topic/11655-ifhelp/#findComment-44373
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.