Jump to content

PHP Include problem


iandotcom

Recommended Posts

Hey,

 

I made a commenting app for my website, and I'm having problems with the include for it to be embedded on its parent page.

 

	<?php

	include ("../iandotcom/comments/comments.php?id=1");		

	?>

 

Its probably really simple, I'm quite new to PHP. I'm running this off my localhost, so thats the root.

Link to comment
https://forums.phpfreaks.com/topic/49528-php-include-problem/
Share on other sites

Same result :(

 

Heres the error message when it fails:

 

Warning: include(../iandotcom/comments/comments.php?id=1) [function.include]: failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs\iandotcom\about\index.php on line 79

 

Warning: include() [function.include]: Failed opening '../iandotcom/comments/comments.php?id=1' for inclusion (include_path='.;C:\Program Files\xampp\php\pear\') in C:\Program Files\xampp\htdocs\iandotcom\about\index.php on line 79

Link to comment
https://forums.phpfreaks.com/topic/49528-php-include-problem/#findComment-242775
Share on other sites

failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs\iandotcom\about\index.php on line 79

 

You need to read and interpret the errors you receive if you want to excel as a developer.  This is telling you that the file you are trying to include does not exist.

 

"But it does exist!" you say.  "I can see it in windows explorer!"

 

Well, in that case you're probably using the wrong path.

 

<?php
include ("./comments/comments.php?id=1");
?>

Link to comment
https://forums.phpfreaks.com/topic/49528-php-include-problem/#findComment-242786
Share on other sites

i believe include and require (and their variants) use the filesystem to include the file so when you pass _GET variables, it will probably search the file system for a file with that name,

 

 

your code probably is looking for a file named 'comments.php?id=1' but only 'comments.php' exists.

 

 

you'd typically use include or require if you want to include the raw PHP code to be processed on the page.

 

you could try this:

<?php
$_GET['id'] = 1;
include ("../iandotcom/comments/comments.php");		
?>

 

 

that might work for you if your code looks for a _GET['id'] to process whatever it is you are processing.

Link to comment
https://forums.phpfreaks.com/topic/49528-php-include-problem/#findComment-242792
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.