Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Filip Grkinic
Filip Grkinic
7,610 Points

url not found after I finished Cleaning URLs with Subfolders

Okey, this is kinda weird and I am kinda lost in between. I downloaded the project code at the end of this part, and it doesnt work, just like mine is not working.

So basicly, everything is working fine expect when I click on one of the shirts for detailed info.

This happens: **https://www.dropbox.com/s/0tgso2c9za6wvt2/Screenshot%202014-07-29%2020.50.13.png

this is my file hierarchy: https://www.dropbox.com/s/8lqhrsg6hhc7e7x/Screenshot%202014-07-29%2020.51.34.png

And here is mine index.php from /shirt folder:

 <?php 

    require_once("../inc/config.php");
    require_once(ROOT_PATH . "inc/products.php");

if (isset($_GET["id"])) {
    $product_id = $_GET["id"];
    if (isset($products[$product_id])) {
        $product = $products[$product_id];
    }
}
if (!isset($product)) {
    header("Location: " . BASE_URL . "shirts/");
    exit();
}

$section = "shirts";
$pageTitle = $product["name"];
include(ROOT_PATH . "inc/header.php"); ?>

        <div class="section page">

            <div class="wrapper">

                <div class="breadcrumb"><a href="<?php echo BASE_URL; ?>shirts/">Shirts</a> &gt; <?php echo $product["name"]; ?></div>

                <div class="shirt-picture">
                    <span>
                        <img src="<?php echo BASE_URL . $product["img"]; ?>" alt="<?php echo $product["name"]; ?>">
                    </span>
                </div>

                <div class="shirt-details">

                    <h1><span class="price">$<?php echo $product["price"]; ?></span> <?php echo $product["name"]; ?></h1>

                    <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
                        <input type="hidden" name="cmd" value="_s-xclick">
                        <input type="hidden" name="hosted_button_id" value="<?php echo $product["paypal"]; ?>">
                        <input type="hidden" name="item_name" value="<?php echo $product["name"]; ?>">
                        <table>
                        <tr>
                            <th>
                                <input type="hidden" name="on0" value="Size">
                                <label for="os0">Size</label>
                            </th>
                            <td>
                                <select name="os0" id="os0">
                                    <?php foreach($product["sizes"] as $size) { ?>
                                    <option value="<?php echo $size; ?>"><?php echo $size; ?> </option>
                                    <?php } ?>
                                </select>
                            </td>
                        </tr>
                        </table>
                        <input type="submit" value="Add to Cart" name="submit">
                    </form>

                    <p class="note-designer">* All shirts are designed by Mike the Frog.</p>

                </div>

            </div>

        </div>

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

Please help me solve this puzzle. Cheers ;)

Can you please paste the code from config.php file?

4 Answers

Filip Grkinic
Filip Grkinic
7,610 Points

sure. When I download project files, they do not work either.

<?php

define("BASE_URL","/");
define("ROOT_PATH",$_SERVER["DOCUMENT_ROOT"] . "/");

That's what I thought. I've made the same mistake and took me awhile to figure it out.

You have to change the BASE_URL and ROOT_PATH in the config.php file, because all your files are in a folder "teamtreehouseshop".

If all the files were right below the htdocs folder (or www folder), then there would be no problem. But now, these paths are pointing wrong.

Try it like this.

define("BASE_URL","/teamtreehousehop/");
define("ROOT_PATH",$_SERVER["DOCUMENT_ROOT"] . "/teamtreehousehop/");

I hope it helps.

Filip Grkinic
Filip Grkinic
7,610 Points

Tnx tihomir.

Unfortunately, when I change "/" to "/teamtreehouseshop/", nothing works anymore.

I think "/" is fine, but for some reason when I click on one of our shirts, this link (http://localhost:8888/shirts/108/) leads to nowhere. Every other page works perfectly.

Hmmm, strange. That was the problem with me and when I fixed the config.php file everything worked again.

Well, the other potential problem file must be the products.php in the inc folder, because this file (get_list_view_html function) is constructing the links to each individual shirt.

Can you paste products.php code too? Just the get_list_view_html function.

Filip Grkinic
Filip Grkinic
7,610 Points

Okey, I figured this out simply by moving on with the lessons. Because next lesson is about shirt.php and shirts.php, and writing rewrite rules and fixing those two pages to work.

I can not believe that I havent heard Hoyt say something in his lessons about those two pages, that those will be fixed in future lessons. Nevermind, everything works fine now, also with the "/" in config.php. :D

Thanks tihomir!