Page 1 of 1

What is wrong with this code ?

Posted: Tue Dec 27, 2005 3:33 am
by roobik
Weirdan | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hi i'm new in php Can you tel me what is wrong ?
This not work in my site !!!!!

Code: Select all

<? if   (file_exists("file/".$page.".php"))
           include ("file/".$page.".php");
	  elseif (include("file/default.php"));
	  ?>
Weirdan | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Re: What is wrong with this code ?

Posted: Tue Dec 27, 2005 3:43 am
by blacksnday
roobik wrote:Hi i'm new in php Can you tel me what is wrong ?
This not work in my site !!!!! :( :cry:


<? if (file_exists("file/".$page.".php"))
include ("file/".$page.".php");
elseif (include("file/default.php"));
?>
need to enclose your if and else statements with curly brackets
and no parenthesis needed before include:

Code: Select all

$page='test1';
if (file_exists("file/".$page.".php")) 
{
	include ("file/".$page.".php"); 
}else{
	include("file/test2.php"); 
}
elseif's are used when having more then one conditional
and in this case it's just one.
also make sure to use php tags when posting code onto forums :)

Re: What is wrong with this code ?

Posted: Tue Dec 27, 2005 3:55 am
by roobik
I try this ! BUT it dont work again :(
If i link a page for example ( index.php?page=about ) dont show the about.php file !!!!!
What i must do ?!

Re: What is wrong with this code ?

Posted: Tue Dec 27, 2005 3:58 am
by blacksnday
My example works and i even tested before posting.
what is your exact code and how are you trying to use it?

Re: What is wrong with this code ?

Posted: Tue Dec 27, 2005 4:41 am
by roobik
I know you example is ok ! but i dont understand why this code dont work in my site ! becouse i use the same in other one and it works normaly ! may this is a php version problem ?!?!
I'm trying to use this code in http://www.hostingmarkets.com for links of this site !

Posted: Tue Dec 27, 2005 6:59 am
by jmut
does it have anything to do with....

http://www.hostingmarkets.com/index.php?page=index.php
http://www.hostingmarkets.com/index.php?page=about

notice that one is ending on .php and the other is not.
This might work on another site but the paths could be wrong and inappropriate for this one.

Posted: Tue Dec 27, 2005 7:41 am
by BDKR
Besides, an error message would be worth it's weight in gold about now. :wink: