Home > Enterprise >  Unable to include the file, but the code does work
Unable to include the file, but the code does work

Time:09-16

I'm trying to print out pdf files from a MySQL database using PHP. Check this link for the 'tutorial' I'm following: https://joshuaotwell.com/php-mysql-blob-pdf-display-in-browser/

I get this warning message: Warning: include(include.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Portfolio\templates\base_html.php on line 2

This happens when I try to include my 'include.php' file, where I connect to the database. The wierd thing to me is that the code does still work and prints out the name of the item in the database. Probably because it's a warning and not an error, but still. Can anyone help me how to clear this message?

Below is the code from my projects.php file.

<?php
include '../include.php';

$sql = "SELECT id, name
        FROM projects
        ORDER BY name ASC;";
$result = $conn->query($sql);
foreach ($result as $row) {
    $records[] = [
        'id' => $row['id'],
        'name' => $row['name']
    ];
}
$title = 'Display PDF File';
ob_start();
include __DIR__ . "\display_html.php";
$output = ob_get_clean();

include __DIR__ . "\base_html.php";

?>

My directory is like this: xampp/htdocs/portfolio/templates My include file is in the portfolio folder and the projects.php file, the code above, is in the templates folder together with the 2 folders called display_html.php and base_html.php.

CodePudding user response:

Well you said, the connection happens in include.php. So the MySQL connection will work, this is true.

But the error you get, is for base_html.php as indicated in the error message.

  • Related