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 Enhancing a Simple PHP Application Adding Search: Controller & View Building the Search Form

project file this not working

i have downloaded the first and second step of this stage and non of the project files seem to be workin? Randy Hoyt Hampton Paulk l hope you guys can help please. the broswer just turns up with a blank screen

1 Answer

Tom Mertz
Tom Mertz
15,254 Points

Did you remember to turn on your local webserver?

EDIT: Did you save the project files directly into your htdocs folder? For example:

htdocs
   index.php
   .htaccess
   shirts/
   search
   inc

Or did you save them into a subfolder in your htdocs?

htdocs
   shirts4mike/
       index.php
       .htaccess
       shirts/
       inc/
       search/

If you did the latter, you'll need to change your config.php file in the inc folder to have a base url of /shirts4mike/ (or whatever your folder is named)

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

l did i am using MAMP and got both severs on. But didnt seem to work.

Tom Mertz
Tom Mertz
15,254 Points

Are you getting any errors, or just a blank screen? Recheck my comment above. I just got the page working by downloading it, so the files are good to go.

l downloaded it straight into my htdocs folder so its got a path of htdocs/project02-stage04-shirts4mike and obviously the files and the sub-folders like the search folder in there. would have to still change the php root like you said above?

Tom Mertz
Tom Mertz
15,254 Points

Yeah, you would have to change you config.php file. If I'm not mistaken you'd have to set your BASE_URL to "/project02-stage04-shirts4mike/ and the same for your ROOT_PATH

Like this

define("BASE_URL", "/project02-stage04-shirts4mike/");
define("ROOT_PATH", $_SERVER["DOCUMENT_ROOT"] . "/project02-stage04-shirts4mike/");

This will also change all the rewrites you'll have to do later, so it might just be easier to copy all of the contents of the project02-stage04-shirts4mike/ folder straight into the htdocs directory.

only problem with copying everything straight into the htdocs is i got other files that and dont want it mix everything up. But the method you described above works perfectly for me only issue am having now is the shirts page wont load part from that everything works pefectly. any ideas about the that or do i need to change its root aswell?

Tom Mertz
Tom Mertz
15,254 Points

That has to do with your rewrites in the .htaccess file. The project files come loaded up with an .htaccess file that assumes you have all the project files right in the htdocs directory. So you have to edit all of the rules to include the name of your folder that the files are in. Here's an example if your folder name was shirts4mike2:

RewriteEngine ON
RewriteRule ^shirts4mike2/shirts/$ /shirts4mike2/shirts/shirts.php
RewriteRule ^shirts4mike2/shirts/([0-9]+)/$ /shirts4mike2/shirts/shirt.php?id=$1
RewriteRule ^shirts4mike2/receipt.php$ /shirts4mike2/receipt/ [R=301]
RewriteRule ^shirts4mike2/contact.php$ /shirts4mike2/contact/ [R=301]
RewriteRule ^shirts4mike2/shirts.php$ /shirts4mike2/shirts/ [R=301]
RewriteRule ^shirts4mike2/contact/thanks/$ /shirts4mike2/contact/?status=thanks

RewriteRule ^(shirts4mike2/shirts/[0-9]+)$ /$1/ [R=301] 

RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^shirts4mike2/shirt.php$ /shirts4mike2/shirts/%1/? [R=301]

Good luck, man.