What is wrong with this code ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
roobik
Forum Newbie
Posts: 10
Joined: Tue Dec 27, 2005 3:15 am

What is wrong with this code ?

Post 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]
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Re: What is wrong with this code ?

Post 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 :)
roobik
Forum Newbie
Posts: 10
Joined: Tue Dec 27, 2005 3:15 am

Re: What is wrong with this code ?

Post 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 ?!
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Re: What is wrong with this code ?

Post by blacksnday »

My example works and i even tested before posting.
what is your exact code and how are you trying to use it?
roobik
Forum Newbie
Posts: 10
Joined: Tue Dec 27, 2005 3:15 am

Re: What is wrong with this code ?

Post 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 !
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post 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.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Besides, an error message would be worth it's weight in gold about now. :wink:
Post Reply