Click to See Complete Forum and Search --> : If, Else If Help


comptech520
09-05-2008, 09:41 AM
When I use the following code, I get this error:

[Fri Sep 05 10:34:34 2008] [error] [client MyIP] PHP Parse error: syntax error, unexpected T_IF, expecting ':' in /var/www/vhosts/mydomain.com/httpdocs/new/includes/right_column_cond.php on line 5



<?php
IF ($_SERVER['SERVER_NAME'] == "www.mydomain.com") :
include ('includes/rc_full.php');
//include path for event types
ELSE IF ($_SERVER['SERVER_NAME'] == "subdomain.mydomain.com") :
include ('includes/rc_mini.php');
//include path for event types
ELSE :
echo "";
ENDIF;
?>

sstalder
09-05-2008, 09:56 AM
PHP is case sensitive so you may want to try this:

if ($_SERVER['SERVER_NAME'] == "www.mydomain.com"):
include ('includes/rc_full.php');
//include path for event types
else if ($_SERVER['SERVER_NAME'] == "subdomain.mydomain.com"):
include ('includes/rc_mini.php');
//include path for event types
else:
echo "";
endif;

NogDog
09-05-2008, 12:21 PM
The case is not an issue, but you need to use ELSEIF (no space) instead of ELSE IF.

<?php
IF ($_SERVER['SERVER_NAME'] == "www.mydomain.com") :
include ('includes/rc_full.php');
//include path for event types
ELSEIF ($_SERVER['SERVER_NAME'] == "subdomain.mydomain.com") :
include ('includes/rc_mini.php');
//include path for event types
ELSE :
echo "";
ENDIF;
?>

You could use "ELSE IF", but then you would actually need to use "ELSE: IF" with an additional layer of nesting:

<?php
IF ($_SERVER['SERVER_NAME'] == "www.mydomain.com") :
include ('includes/rc_full.php');
//include path for event types
ELSE:
IF ($_SERVER['SERVER_NAME'] == "subdomain.mydomain.com") :
include ('includes/rc_mini.php');
//include path for event types
ELSE :
echo "";
ENDIF;
ENDIF;
?>