Page 1 of 1

if statement help

Posted: Mon Aug 28, 2006 4:47 pm
by jasondavis
Below is my code I am using on a page it worked fine for showing my flash chat if name was set in a session and showing a message instead if name wasnt set yet, Now though I need to show a different chat if there age is over a certain again in the middle of the code you will see where I need this added I am lost any help greatly appreciated

Code: Select all

<?PHP
$age ='12';
session_start(); // need to be called once 
 if ($l=$_SESSION['mycribname']) { ?>
     
<html>
<head>
<title>MyCribTrain.com - MyCrib Chat</title>
<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100%" height="100%">
<param name=movie value="123flashchat.swf?init_listroom=1001,3,4,5,6">
<param name=quality value=high>
<embed src="123flashchat.swf?init_listroom=1001,3,4,5,6" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100%" height="100%" >
</embed>
</object>

</body>
</html>
<? need code here if session for name is set and $age > 18 ?>
<html>
<head>
<title>MyCribTrain.com - MyCrib Chat</title>
<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100%" height="100%">
<param name=movie value="123flashchat.swf?init_user=<?=$_SESSION['mycribname'];?>&init_password=">
<param name=quality value=high>
<embed src="123flashchat.swf?init_user=<?=$_SESSION['mycribname'];?>&init_password=" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100%" height="100%" >
</embed>
</object>

</body>
</html>
 <? } else { ?>
You must come from Mycrib.net to enter the chat <a href="http://mycrib.net/?pageid=mycrib.member.profile.home">Click here</a>
<? } ?>

Posted: Mon Aug 28, 2006 4:57 pm
by blackbeard
You mean something like this:

Code: Select all

$age = 12;  //  Use an integer instead of a string

if ((isset($_SESSION['mycribname'])  && ($age >= 18)) {

//  output html for people 18 and over

}

else if ((isset($_SESSION['mycribname'])  && ($age < 18)) {

// output html for people under 18

}

else {

// Output message to make them go to url

}

Posted: Mon Aug 28, 2006 5:14 pm
by jasondavis
exactly what i need but im getting this

Parse error: parse error, unexpected '{' in /home/mycrib/public_html/chat/index2.php on line 4

line 4=

Code: Select all

if ((isset($_SESSION['mycribname'])  && ($age >= 88)) {


my whole code now

Code: Select all

<?PHP
$age =12;
session_start(); // need to be called once 
if ((isset($_SESSION['mycribname'])  && ($age >= 88)) {
?>

<html>
<head>
<title>MyCribTrain.com - MyCrib Chat</title>
<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>	
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100%" height="100%">
<param name=movie value="123flashchat.swf?init_user=<?=$_SESSION['mycribname'];?>&init_password=&init_listroom=1001,1002,1003,1004,1005">
<param name=quality value=high>
<embed src="123flashchat.swf?init_user=<?=$_SESSION['mycribname'];?>&init_password=&init_listroom=1001,1002,1003,1004,1005" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100%" height="100%" >
</embed>
</object>
</body>
</html>
<? } else if ((isset($_SESSION['mycribname'])  && ($age < 18)) { ?>
<html>
<head>
<title>MyCribTrain.com - MyCrib Chat</title>
<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>	
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100%" height="100%">
<param name=movie value="123flashchat.swf?init_user=<?=$_SESSION['mycribname'];?>&init_password=&init_listroom=1001,1002,1003,1004">
<param name=quality value=high>
<embed src="123flashchat.swf?init_user=<?=$_SESSION['mycribname'];?>&init_password=&init_listroom=1001,1002,1003,1004" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100%" height="100%" >
</embed>
</object>
</body>
</html>
<? } else { ?>
You must come from Mycrib.net to enter the chat <a href="http://mycrib.net/?pageid=mycrib.member.profile.home">Click here</a>
<? } ?>

Posted: Mon Aug 28, 2006 5:16 pm
by feyd
pair up the parens... you're missing a few.

Posted: Mon Aug 28, 2006 5:25 pm
by blackbeard
Personally, I don't like using multiple <?php ?> tags, it's too easy for me to miss things like brackets. You may want to use the heredoc syntax, IMHO, less trouble, and easier to maintain. Your code using heredoc syntax would look like this:

Of course, you don't have to, do it however you're comfortable with.

edit: didn't notice that other embed php tags, look at the next post for a better way.

Posted: Mon Aug 28, 2006 5:25 pm
by jasondavis
feyd wrote:pair up the parens... you're missing a few.
a raen is ( correct?
if so i tried paring them with no luck

Posted: Mon Aug 28, 2006 5:30 pm
by jasondavis
thanks I do like this method better but I still get error with that code

Parse error: parse error, unexpected '{' in /home/mycrib/public_html/chat/index2.php on line 5

blackbeard wrote:Personally, I don't like using multiple <?php ?> tags, it's too easy for me to miss things like brackets. You may want to use the heredoc syntax, IMHO, less trouble, and easier to maintain. Your code using heredoc syntax would look like this:

Code: Select all

<?PHP
session_start();
$age =12;
session_start(); // need to be called once
if ((isset($_SESSION['mycribname'])  && ($age >= 18)) {

echo<<<SECTION1
<html>
<head>
<title>MyCribTrain.com - MyCrib Chat</title>
<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head> 
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100%" height="100%">
<param name=movie value="123flashchat.swf?init_user=<?=$_SESSION['mycribname'];?>&init_password=&init_listroom=1001,1002,1003,1004,1005">
<param name=quality value=high>
<embed src="123flashchat.swf?init_user=<?=$_SESSION['mycribname'];?>&init_password=&init_listroom=1001,1002,1003,1004,1005" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100%" height="100%" >
</embed>
</object>
</body>
</html>
SECTION1;

} 
else if ((isset($_SESSION['mycribname'])  && ($age < 18)) { 

echo<<<SECTION2
<html>
<head>
<title>MyCribTrain.com - MyCrib Chat</title>
<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head> 
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100%" height="100%">
<param name=movie value="123flashchat.swf?init_user=<?=$_SESSION['mycribname'];?>&init_password=&init_listroom=1001,1002,1003,1004">
<param name=quality value=high>
<embed src="123flashchat.swf?init_user=<?=$_SESSION['mycribname'];?>&init_password=&init_listroom=1001,1002,1003,1004" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100%" height="100%" >
</embed>
</object>
</body>
</html>
SECTION2;
} else { 

echo "You must come from Mycrib.net to enter the chat <a href="http://mycrib.net/?pageid=mycrib.member.profile.home">Click here</a>";
 } 

?>
Of course, you don't have to, do it however you're comfortable with.

Posted: Mon Aug 28, 2006 5:30 pm
by Christopher
This is a great example of why you should separeate your programming from your presentation. It makes it much easier to see what is going on and promotes reuse.

Here is the actual program:

Code: Select all

<?PHP
$age =12;
session_start(); // need to be called once 
if ((isset($_SESSION['mycribname'])  && ($age >= 88)) {
     $params = 'init_user=' . $_SESSION['mycribname'] . '&init_password=&init_listroom=1001,1002,1003,1004';
     include 'templates/chat.php';
} else if ((isset($_SESSION['mycribname'])  && ($age < 18 )) {
     $params = 'init_user=&init_listroom=1001,1002,1003,1004';
     include 'templates/chat.php';
} else {
     echo 'You must come from Mycrib.net to enter the chat <a href="http://mycrib.net/?pageid=mycrib.member.profile.home">Click here</a>';
}
 ?>
This is the presentation stuff in chat.php:

Code: Select all

<html>
<head>
<title>MyCribTrain.com - MyCrib Chat</title>
<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>	
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100%" height="100%">
<param name=movie value="123flashchat.swf?<?php echo $params; ?>">
<param name=quality value=high>
<embed src="123flashchat.swf?<?php echo $params; ?>" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100%" height="100%" >
</embed>
</object>
</body>
</html>

Posted: Mon Aug 28, 2006 5:38 pm
by jasondavis
interesting way to do it, but this still creates same error as other ways tried

Parse error: parse error, unexpected '{' in /home/mycrib/public_html/chat/index2.php on line 4

arborint wrote:This is a great example of why you should separeate your programming from your presentation. It makes it much easier to see what is going on and promotes reuse.

Here is the actual program:

Code: Select all

<?PHP
$age =12;
session_start(); // need to be called once 
if ((isset($_SESSION['mycribname'])  && ($age >= 88)) {
     $params = 'init_user=' . $_SESSION['mycribname'] . '&init_password=&init_listroom=1001,1002,1003,1004';
     include 'templates/chat.php';
} else if ((isset($_SESSION['mycribname'])  && ($age < 18 )) {
     $params = 'init_user=&init_listroom=1001,1002,1003,1004';
     include 'templates/chat.php';
} else {
     echo 'You must come from Mycrib.net to enter the chat <a href="http://mycrib.net/?pageid=mycrib.member.profile.home">Click here</a>';
}
 ?>
This is the presentation stuff in chat.php:

Code: Select all

<html>
<head>
<title>MyCribTrain.com - MyCrib Chat</title>
<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>	
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100%" height="100%">
<param name=movie value="123flashchat.swf?<?php echo $params; ?>">
<param name=quality value=high>
<embed src="123flashchat.swf?<?php echo $params; ?>" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100%" height="100%" >
</embed>
</object>
</body>
</html>

Posted: Mon Aug 28, 2006 6:21 pm
by feyd
still missing the same parens..

yes, parens are "(" and ")"

Posted: Mon Aug 28, 2006 6:39 pm
by Christopher
You are a patient soul feyd. :D

Posted: Mon Aug 28, 2006 7:23 pm
by RobertGonzalez
For the program part of it, you could do something like...

Code: Select all

<?php
session_start(); // need to be called once

$age = 12;
$msg = '';
if ( isset($_SESSION['mycribname']) )
{
    if ( $age >= 88 )
	{
	    $params = 'init_user=' . $_SESSION['mycribname'] . '&init_password=&init_listroom=1001,1002,1003,1004';
	}
	else if ( $age < 18 )
	{
	    $params = 'init_user=&init_listroom=1001,1002,1003,1004';
	}
	
	include 'templates/chat.php';
}
else
{
    $msg = 'You must come from Mycrib.net to enter the chat <a href="http://mycrib.net/?pageid=mycrib.member.profile.home">Click here</a>';
}

echo $msg; // Or use this in your HTML somewhere
?>