user6559259
user6559259

Reputation: 11

PHP include(); not including file

I am trying to include a separate snippet of code to fetch data from MySQL tables. My page code:

<?php session_start(); ?>
<html>
    <?php include('head.php'); ?>
    <body>
        <?php include('navigation.php'); ?>
        <div id="container">
        <?php
            $section = "Movies";
            print "THIS IS A TEST";
            //$_SESSION['sectiontemp'] = $section;
            include('section-grabinfo.php');
            include('footer.php');
        ?>
        </div>
    </body>
</html>

My section-grabinfo.php page:

<?php
            print "THIS IS A TEST";
            $sql = mysqli_query($conn, "SELECT * FROM article JOIN person ON article.author=person.id WHERE section='".$section."' AND status=1 ORDER BY aid DESC LIMIT 1;");
            if ($sql == 'false') {
                print "SQL doesn't work";
            }
            elseif ($sql == 'true') {
                print "Works all fine";
            }
            else {
                print "Wrong code.";
            }
            while ($row = mysqli_fetch_assoc($sql)) {
                $title = $row['title'];
                $preview = $row['preview'];
                $author = $row['name'];
                $person_id = $row['author'];
                $id = $row['id'];
                $username = $row['username'];
                include('featured-article.php');
            }
            //LEAVE SPACE FOR ADS
?>
<div id="secondaryArticleSection">
<?php
            $sql2 = mysqli_query($conn, "SELECT * FROM article JOIN person ON article.author=person.id WHERE aid<(SELECT max(aid) FROM article WHERE section='."$section."' AND status=1) AND section='".$section."' AND status=1 ORDER BY aid DESC;");
            while ($row = mysqli_fetch_assoc($sql2)) {
                $title = $row['title'];
                $preview = $row['preview'];
                $author = $row['name'];
                $person_id = $row['author'];
                $id = $row['id'];
                $username = $row['username'];
                include('secondary-article.php');
            }
?>
</div>

Basically my problem is that section-grabinfo.php and footer.php are not being included on the main page. Please keep in mind that this worked completely when I had this on my laptop computer (not the server I'm currently working with). Thank you.

Upvotes: 1

Views: 110

Answers (1)

AlexisWbr
AlexisWbr

Reputation: 451

If it is really an including trouble, you could try to include this way

<?php include(__DIR__.'/head.php'); ?>

Upvotes: 1

Related Questions