-3

The file i'm working with is in the same directory as the file i'm trying to include. include('/display_projects.php') (i've tried many different variations on this, none resulting in error, and none display the contents of the file)

inside display_projects.php:

<?php
echo "<body><h3>TEST</h3></body>"
?>

Test is not showing up anywhere on the page, any help would be appreciated.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Plsx
  • 1
  • 1
  • There are no errors? Is the missing semicolon from the end of your echo line a typo here or is that the error? Or perhaps the leading slash which would mean it's not relative anymore – James Apr 11 '18 at 00:36
  • Missing semi colon was a typo, my bad haha and yes, no errors – Plsx Apr 11 '18 at 00:38
  • are you sure error checking and display are on? –  Apr 11 '18 at 00:39
  • you could try changing include to require, to make sure it is loaded – Andrew Apr 11 '18 at 00:41
  • right click and view source. Is anything there? Can you confirm you are looking at your server error log and there are none? – James Apr 11 '18 at 00:42
  • What does this result in: `var_dump(is_file('display_projects.php'));`? – James Apr 11 '18 at 00:54
  • 4
    Your update is totally not what you first posted :( and is completely another issue to the red herring missing semi colons and leading slash :( "*If I set the include to the top of the page, outside of the echo it works*" you said it didn't based on the code provided :( – James Apr 11 '18 at 00:57
  • Read @James answer, that should solve your problem. Check [How to accept an answer](https://meta.stackexchange.com/a/5235/387979) – Spoody Apr 11 '18 at 01:08
  • I've rolled the question back to its original state @James However, the question was closed and marked for deletion. This one's not going to get any better so I'd just count your losses, for everyone actually. I'm not going to keep an eye out for this question, but if you see anymore invalid updates, you can flag the question for moderation. This is "your" choice. Which way that will go, I can't speak for them (moderators). – Funk Forty Niner Apr 11 '18 at 01:21
  • not sure why the rollback as the problem and answer is from the update. But if it's being deleted then meh :) OP has their answer and better for the site :) – James Apr 11 '18 at 01:25

4 Answers4

1

echo is for outputting, not calling and running includes as you have tried.

You can do something like this:

echo '<html><body>';
include 'display_projects.php';
echo '</body></html>';
James
  • 4,644
  • 5
  • 37
  • 48
  • 1
    Did he just completely change the question... WTH! – Spoody Apr 11 '18 at 01:02
  • 2
    Yeah sadly, the (red herring) issues in the code originally given were defo legit issues to be mentioned, and now obsolete. Hopefully they'll take note of the reason why not giving good info in the first place makes it hard to help :) – James Apr 11 '18 at 01:06
0

Usually how I do it.

In the same directory:

include __DIR__ .'/my_file.php';

Up one directory:

include __DIR__ .'/../my_file.php';
Andrew
  • 18,680
  • 13
  • 103
  • 118
0

Make the path like that

include('./display_projects.php')

note that :
./ means in the same directory

0

There are no errors most likely because they are silenced. You can show them by calling

ini_set( 'error_reporting', E_ALL );
ini_set( 'display_errors', true );

on the top of your script.

To include file in current directory, you have to prefix your file name with dot and slash

include './display_projects.php';

By prefixing the file with slash only you are saying you want to include file located in the server root directory.

jirig
  • 551
  • 6
  • 21