/    Sign up×
Community /Pin to ProfileBookmark

can anyone take a look at this script?

page.php

1 <a href=”article.php?article=index”>Index</a><br>
2 <a href=”article.php?article=aboutus”>About Us</a><br>
3 <a href=”article.php?article=business”>Business </a><br>
<?
$article = (isset($_GET[‘article’])) ? $_GET[‘article’] : ‘index’;
include(“$article.php”);
if (isset($_GET[‘index’]))
{
$index=$_
GET[‘index’];

$aboutus=$_GET[‘aboutus’];
$chicken=”article”;
include(“$article.php”);
}
else
{
$chicken=”$article.php”;
include(“$article”);
}
?>

the index page(1) and the aboutus(2) page works since they’re in the same location with this file. But the business(3)page is located in a sub folder. What possibly might be the solution? thanks in advanced.
it’s for article pages. The links would be like

[url]www.server.com/article/?article=study[/url]
[url]www.server.com/article/?article=math[/url]
[url]www.server.com/article/?article=computer[/url]
or
[url]www.server.com/article/page.php?article=study[/url]
[url]www.server.com/article/page.php?article=math[/url]
[url]www.server.com/article/page.php?article=computer[/url]

to post a comment
PHP

15 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyMar 21.2006 — ...

$article = (isset($_GET['article'])) ? $_GET['article'] : 'index';

if($article == "business")

$article = "subfoldername".$article;

include("$article.php");

...
Copy linkTweet thisAlerts:
@MichaelttkkauthorMar 21.2006 — I tried various way but it still shows error like

Warning: main(index): failed to open stream: No such file or directory in /web/users/samdol/articles.php on line 33

Warning: main(): Failed opening 'index' for inclusion (include_path='.:/usr/local/lib/php') in /web/users/samdol/articles.php on line 33

could you please give a full code? 2 anchor links from same directory while the other one or many more files will be from subfolder

and this section

{

$index=$_GET['index'];

$aboutus=$_
GET['aboutus'];

$chicken="article";

include("$article.php");

}

I think is related to database which I don't need; I got this code from a friend ,
Copy linkTweet thisAlerts:
@bathurst_guyMar 22.2006 — I dont see where it is referencing this error in this code. What is on line 33?
Copy linkTweet thisAlerts:
@MichaelttkkauthorMar 22.2006 — article.php

13

14

15 <table align="center" width="600" border="0" cellspacing="0" cellpadding="0">

16 <tr border="0"><td width="740" height="100">

17 <a href="article.php?article=index">Index</a><br>

18 <a href="article.php?article=aboutus">About Us</a><br>

19 <a href="article.php?article=business">Business </a><br>

20 <?

21 $article = (isset($_GET['article'])) ? $_GET['article'] : 'index';

22 include("$article.php");

23 if (isset($_GET['index']))

24 {

25 $index=$_
GET['index'];

26 $aboutus=$_GET['aboutus'];

27 $chicken="article";

28 include("$article.php");

29 }

30 else

31 {

32 $chicken="$article.php";

33 include("$article");

34 }

35 ?>

36

37

index.php and aboutus.php are in the same directory with article.php

(www.server.com/articles.php)/

(www.server.com/aboutus.php)

but the business.php is in the subdirectory

(www.server.com/article/business.php)

here is the result on click of <a href="article.php?article=business">Business </a>

Index (working link)

About Us (working link)

Business (not working)

Warning: main(business.php): failed to open stream: No such file or directory in /web/users/samdol/articles.php on line 22

Warning: main(): Failed opening 'business.php' for inclusion (include_path='.:/usr/local/lib/php') in /web/users/samdol/articles.php on line 22

Warning: main(business): failed to open stream: No such file or directory in /web/users/samdol/articles.php on line 33

Warning: main(): Failed opening 'business' for inclusion (include_path='.:/usr/local/lib/php') in /web/users/samdol/articles.php on line 33


-----------------------------
And I tried inserting the code of yours,

20 <?

21 $article = (isset($_GET['article'])) ? $_GET['article'] : 'index';

22 if($article == "business")

23 $article = "article".$article;

24 include("$article.php");

25 {

26 $index=$_GET['index'];

27 $aboutus=$_
GET['aboutus'];

28 $chicken="article";

29 include("$article.php");

30 }

31 else

32 {

33 $chicken="$article.php";

34 include("$article");

35 }

36 ?>

in a black page there's this at the top

Parse error: parse error, unexpected T_ELSE in /web/users/samdol/articles.php on line 31
Copy linkTweet thisAlerts:
@SheldonMar 22.2006 — What has happened to the use of your VB Tags?

Try a switch, i think is may be a batter use of what you are doing

[code=php]

//<a href="article.php?article=index">Index</a><br>
//<a href="article.php?article=aboutus">About Us</a><br>
//<a href="article.php?article=business">Business </a><br>
<?php

# #
# Put this in a file called "article.php" #
# #

if(isset($_GET['article'])){
$article = $_GET['article'];
}else{
$article = "index";
}
switch($article){

case "index":
//case is index
include("index.php");
break;

case "aboutus":
//case is aboutus
include("aboutus.php");
break;

case "business":
//case is business
include("business.php");
break;

default:
//doesnt match
include($article.".php");
break;

}

//I dont understand what you are trying to do with anything else there
?>[/code]
Copy linkTweet thisAlerts:
@MichaelttkkauthorMar 22.2006 — sorry about this but it returns the same out come

Warning: main(business.php): failed to open stream: No such file or directory in /web/users/samdol/articles.php on line 46

Warning: main(): Failed opening 'business.php' for inclusion (include_path='.:/usr/local/lib/php') in /web/users/samdol/articles.php on line 46

21 <?php

22

23 # #

24 # Put this in a file called "article.php" #

25 # #

26


27 if(isset($_GET['article'])){

28 $article = $_
GET['article'];

29 }else{

30 $article = "index";

31 }

32 switch($article){

33

34 case "index":

35 //case is index

36 include("index.php");

37 break;

38


39 case "aboutus":

40 //case is aboutus

41 include("aboutus.php");

42 break;

43

44 case "business":

45 //case is business

46 include("business.php");

47 break;

48

49 default:

50 //doesnt match

51 include($article.".php");

52 break;

53


54 }

55

56

57 ?>
Copy linkTweet thisAlerts:
@SheldonMar 22.2006 — Well read the errors then And you still didnt use VB tags (Duh - [ php ] code here [/ php ]).

Your error is
Failed opening 'business.php'[/quote]
Is business.php in the same folder as your article?

are the all in the same folder?

If not post the locations of both the files to be included and article.php
Copy linkTweet thisAlerts:
@MichaelttkkauthorMar 22.2006 — one thing that I'm sure is, business.php is in (www.server.com/article/business.php) the subfolder.

articles.php is in the same directory as index.php (www.server.com/articles.php)

I've just heard of VB tags and Googled itand found [code=php]code[/code] but still got to find out more
Copy linkTweet thisAlerts:
@MichaelttkkauthorMar 22.2006 — [code=html]<table align="center" width="600" border="0" cellspacing="0" cellpadding="0">
<tr border="0"><td width="740" height="100">
<a href="article.php?article=index">Index</a><br>
<a href="article.php?article=aboutus">About Us</a><br>
<a href="article.php?article=business">Business </a><br>

<?php


if(isset($_GET['article'])){
$article = $_GET['article'];
}else{
$article = "index";
}
switch($article){

case "index":
//case is index
include("index.php");
break;

case "aboutus":
//case is aboutus
include("aboutus.php");
break;

case "business":
//case is business
include("business.php");
break;

default:
//doesnt match
include($article.".php");
break;

}

?>
[/code]
Copy linkTweet thisAlerts:
@bathurst_guyMar 22.2006 — I like the idea of a switch, but I would do it this way.
[code=php]<?
$article = ((isset($_GET['article']))?$_GET['article']:"index");
switch($article){
case "business":
include("article/business.php");
break;

default:
//doesnt match
include($article.".php");
break;
}
?>
[/code]
Copy linkTweet thisAlerts:
@SheldonMar 22.2006 — Replace the code with this then, You have to reference the included file just like any other.
[code=php]

<?php

# #
# Put this in a file called "article.php" #
# #

if(isset($_GET['article'])){
$article = $_GET['article'];
}else{
$article = "index";
}
//set the directory of where the file is in relation to this script
$dir = "article/"; // dont forget the trailing slash
switch($article){

case "index":
//case is index
include($dir."index.php");
break;

case "aboutus":
//case is aboutus
include($dir."aboutus.php");
break;

case "business":
//case is business
include($dir."business.php");
break;

default:
//doesnt match
include($dir.$article.".php");
break;

}

?>[/code]
Copy linkTweet thisAlerts:
@SheldonMar 22.2006 — ssdd
Copy linkTweet thisAlerts:
@MichaelttkkauthorMar 22.2006 — Thanks Sheldon! It works now.

I changed
[code=php]
case "business":
//case is business (not for subfolder files)
include("business.php");
break;
[/code]

To
[code=php]
case "business":
//case is business (for subfolder files)
include("article/business.php");
break;
[/code]


Thanks again, Sheldon.
Copy linkTweet thisAlerts:
@MichaelttkkauthorMar 22.2006 — I didn't see bathurst_guy's code
[code=php]
<?
$article = ((isset($_GET['article']))?$_GET['article']:"index");
switch($article){
case "business":
include("article/business.php");
break;

default:
//doesnt match
include($article.".php");
break;
}
?>
[/code]


It works, too. Thanks to you too, bathurst_guy.
×

Success!

Help @Michaelttkk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...