Connecting to an external PHP file

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

AngelGirl88
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Dec 10, 2012 11:23 am

Connecting to an external PHP file

Postby AngelGirl88 » Mon Dec 10, 2012 11:33 am

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 :help:

User avatar
Barrikor
New php-forum User
New php-forum User
Posts: 16
Joined: Sun Dec 12, 2010 3:14 pm

Re: Connecting to an external PHP file

Postby Barrikor » Mon Dec 10, 2012 6:15 pm

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 '

AngelGirl88
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Dec 10, 2012 11:23 am

Re: Connecting to an external PHP file

Postby AngelGirl88 » Mon Dec 10, 2012 7:09 pm

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. :?

User avatar
Barrikor
New php-forum User
New php-forum User
Posts: 16
Joined: Sun Dec 12, 2010 3:14 pm

Re: Connecting to an external PHP file

Postby Barrikor » Mon Dec 10, 2012 8:56 pm

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

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

AngelGirl88
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Dec 10, 2012 11:23 am

Re: Connecting to an external PHP file

Postby AngelGirl88 » Tue Dec 11, 2012 10:15 am

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
New php-forum User
Posts: 6
Joined: Mon Dec 10, 2012 11:23 am

Re: Connecting to an external PHP file

Postby AngelGirl88 » Tue Dec 11, 2012 10:16 am

Is there another way to include an external PHP file that I haven't thought of?

User avatar
Barrikor
New php-forum User
New php-forum User
Posts: 16
Joined: Sun Dec 12, 2010 3:14 pm

Re: Connecting to an external PHP file

Postby Barrikor » Tue Dec 11, 2012 11:11 am

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?

AngelGirl88
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Dec 10, 2012 11:23 am

Re: Connecting to an external PHP file

Postby AngelGirl88 » Wed Dec 12, 2012 6:43 am

I actually managed to figure it out, thank you for your help


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest