Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Simple PHP Application Working With Functions Creating the Shirt Display Function

Master Marketing
Master Marketing
1,200 Points

My index.php's product listing page doesn't work anymore after using the get_list_view_html function

My shirts.php page works fine but on the index.php, I get this error:

Notice: Use of undefined constant inc - assumed 'inc' in C:\xampp\htdocs\shirts4mike\index.php on line 28

Notice: Use of undefined constant products - assumed 'products' in C:\xampp\htdocs\shirts4mike\index.php on line 28

Warning: Division by zero in C:\xampp\htdocs\shirts4mike\index.php on line 28

Notice: Use of undefined constant php - assumed 'php' in C:\xampp\htdocs\shirts4mike\index.php on line 28

Warning: include(C:\xampp\php\pear\PHP): failed to open stream: Permission denied in C:\xampp\htdocs\shirts4mike\index.php on line 28

Warning: include(): Failed opening 'php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\shirts4mike\index.php on line 28

Notice: Undefined variable: products in C:\xampp\htdocs\shirts4mike\index.php on line 31

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\shirts4mike\index.php on line 31

Here's my code

<?php 
$pageTitle = "Unique T-shirts designed by a frog";
$section = "home";

include('inc/header.php'); ?>

        <div class="section banner">

            <div class="wrapper">

                <img class="hero" src="img/mike-the-frog.png" alt="Mike the Frog says:">
                <div class="button">
                    <a href="shirts.php">
                        <h2>Hey, I&rsquo;m Mike!</h2>
                        <p>Check Out My Shirts</p>
                    </a>
                </div>
            </div>

        </div>

        <div class="section shirts latest">

            <div class="wrapper">

                <h2>Mike&rsquo;s Latest Shirts</h2>

                <?php include(inc/products.php); ?>

                <ul class="products">
                    <?php foreach($products as $product_id => $product) { 
                        echo get_list_view_html($product_id, $product); 
                    }
                ?>                          
                </ul>

            </div>

        </div>


<?php include('inc/footer.php'); ?>

I used the same foreach loop as what we used in the shirts.php. Any help is very much appreciated. Thanks guys!

1 Answer

<?php include(inc/products.php); ?>

you forgot to quote the argument

Master Marketing
Master Marketing
1,200 Points

Oh does it have to be in quotes?

Master Marketing
Master Marketing
1,200 Points

Oh I get what you mean now. Thanks! -.- I totally overlooked this.

Has this solved your problem?

It's this line right?

<?php

include(inc/products.php);

should be:

<?php

include('inc/products.php');