## Connecting to an external PHP file

Moderators: macek, egami, gesf

### Connecting to an external PHP file

I'm attempting to connect to an events calendar page from within a working php site. The main code works perfectly fine, and the events calendar comes up the way its supposed to however, when I try to include the file as a condition of a true if statement I get the errors:

Warning: include(..\public\calendar.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\st_james_public\index.php on line 19

Warning: include() [function.include]: Failed opening '..\public\calendar.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\st_james_public\index.php on line 19

The code for the main index page is as follows:

Code: Select all
`<?php   \$page_title = 'Home';   include("header.php");         if ((isset(\$_GET['PageID'])) && (is_numeric(\$_GET['PageID']))){      \$pageID = \$_GET['PageID'];   }else{      \$pageID = 1;   }            james_connect();   \$SQL = "SELECT * FROM james_pages , james_content WHERE james_content.james_pages_pageID = james_pages.pageID && james_pages.pageID = \$pageID";   \$results = mysql_query(\$SQL) or die(mysql_error());      if (\$pageID == 6){      include("..\public\calendar.php");   }      while (\$row = mysql_fetch_array(\$results)) {      echo ("<h4>\${row["contentTitle"]}</h4>");      echo ("<p>\${row["contentContent"]}</p>");   }   james_close();   include("footer.php");?>`

and the issue arises at the line with:
Code: Select all
`if (\$pageID == 6){   include("..\public\calendar.php");}`

I'm completely stumped..any help would be appreciated
AngelGirl88
New php-forum User

Posts: 6
Joined: Mon Dec 10, 2012 11:23 am

### Re: Connecting to an external PHP file

You appear to be running PHP on Windows..? WAMP setup?

Your include() is using a double-quote string "xxxxx" not single-quote 'xxxx', double-quoted strings will parse for escape sequences so using a backslash can mess things up, maybe the \c is doing something. See if the error changes if you change each " into a '

Barrikor
New php-forum User

Posts: 16
Joined: Sun Dec 12, 2010 3:14 pm

### Re: Connecting to an external PHP file

I've changed all " to ' and the same two errors occur. The setup is XAMPP instead of WAMP as well however it is on windows.. I've also tried it with the forward slash as well and its the same thing.
AngelGirl88
New php-forum User

Posts: 6
Joined: Mon Dec 10, 2012 11:23 am

### Re: Connecting to an external PHP file

I can't think of any other problem...

Have you tried seeing what happens if you test it with an absolute path?

Barrikor
New php-forum User

Posts: 16
Joined: Sun Dec 12, 2010 3:14 pm

### Re: Connecting to an external PHP file

If I change it to an absolute path it throws other errors that have to do with connecting in internal initialization files for the calendar to work, which have no issues when the calendar is run separately
AngelGirl88
New php-forum User

Posts: 6
Joined: Mon Dec 10, 2012 11:23 am

### Re: Connecting to an external PHP file

Is there another way to include an external PHP file that I haven't thought of?
AngelGirl88
New php-forum User

Posts: 6
Joined: Mon Dec 10, 2012 11:23 am

### Re: Connecting to an external PHP file

On Linux the file/folder permissions can mess thing up sometimes but I don't think that could be a problem on windows... But maybe try coping the file (and associated files?) into the same folder as your script, then trying to include them?

Barrikor
New php-forum User

Posts: 16
Joined: Sun Dec 12, 2010 3:14 pm

### Re: Connecting to an external PHP file

I actually managed to figure it out, thank you for your help
AngelGirl88
New php-forum User

Posts: 6
Joined: Mon Dec 10, 2012 11:23 am