PDA

View Full Version : if-else


jmm
Sun 20th May '01, 8:26am
why can't this work?

if you're a member and logged on, see a "thank you" message. Otherwise, see an "error" message.
Here is the code:

<?php
require( "./global.php" );
?>

<?php

if( $bbuserid ) {$user = $DB_site->query_first( "SELECT username FROM user WHERE userid = $bbuserid" );$bbuserinfo = $user[ username ];

print( "<BODY BGCOLOR=\"#000000\"><CENTER><FONT FACE=\"verdana, arial\" size=\"2\" color=\"white\">Thanks, you are logged on!</font><br>" );

} else {
print( "<BODY BGCOLOR=\"#000000\"><CENTER><FONT FACE=\"verdana,arial\"size=\"2\"color=\"white\">Sorry, login required!</font><br>" );

}

?>

help would be appreciated

Kier
Sun 20th May '01, 10:11am
if ($bbuserinfo[userid]==0) {
// not logged in stuff
} else {
// logged in stuff
}

Mas*Mind
Sun 20th May '01, 10:18am
You don't need this part:

$user = $DB_site->query_first( "SELECT username FROM user WHERE userid = $bbuserid" );$bbuserinfo = $user[ username ];

All those info is allready available by including global.php; This should work:


<?php
require("./global.php");
?>

<?php

if($bbuserinfo[userid]!=0)
{ print("<BODY BGCOLOR=\"#000000\"><CENTER><FONT FACE=\"verdana, arial\" size=\"2\" color=\"white\">Thanks, you are logged on!</font><br>");
}
else
{ print("<BODY BGCOLOR=\"#000000\"><CENTER><FONT FACE=\"verdana,arial\"size=\"2\"color=\"white\">Sorry, login required!</font><br>");
}

?>


$bbuserinfo[username] contains the username

jmm
Sun 20th May '01, 10:49am
Thanks for the quick reply. I will edit the file as suggested.

jmm
Sun 20th May '01, 11:14am
I have done the editing and it works just fine. Thanks. But, here is the reason why I was playing around with this code:

If you are a member and logged on, then you should gain access to "games.php"

If you are not a member, then you can not play any game.

Now that the if-else part is working, how exactly would the "if" part load up the "game.php" and the "else" part load the "error.php". Is this possible at all without the use of templates?

Also, I am thinking one would have to have the code below in all games.php files incase visistors bookmarked the pages. Am I right.

Thanks again

<?php
require("./global.php");
?>