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 Creating the Search Page

Eric Schweitzer
Eric Schweitzer
4,027 Points

Errors with newly downloaded project files

I downloaded and copied the new project files into my main course folder and now I'm getting errors that prevent anything from displaying. My php_log file shows this:

Undefined variable: product_id in C:\wamp\www\Build a Simple PHP Application\includes\products.php on line 34

and also

Undefined variable: products in C:\wamp\www\Build a Simple PHP Application\index.php on line 35

Am I missing something simple?

Thanks!

6 Answers

Jesse Reckley
Jesse Reckley
28,469 Points

uhhh... Did you put the whole file in you local host file? cause then you will have to add the file name to it: like I changed the folder name to "shirts4mike" so I had to edit the config file:

html <p>define("BASE_URL","/shirts4mike/");</p><br/> <p>define("ROOT_PATH",$_SERVER["DOCUMENT_ROOT"] . "/shirts4mike/");</p> l

and the .htaccess file:

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

Make sense? Anyway maybe that clears up some of the problems.

I think this particular method has room for improvement. I say this because I'm considering the amount of code you would have to change in the future if you had to rename or move your folders around. To me, .htaccess should already be looking in your shirts4mike folder without you having to specifically point to it.

I don't know what local server you're using, but it sounds like you haven't set the route of the project to the shirts4mike folder. If you do that, you can remove the shirts4mike directory from your .htaccess file and it becomes a little more dynamic.

e.g. it is likely you would have to have different .htaccess files for local/live development. Not the worst thing, but extra admin you don't have to deal with. Changing the root of your project instead of the .htaccess file will work in your favour. By updating your server root, when you make changes you would only have to change the directory where your server is pointing, not the entire .htaccess file.

Ben Attenborough
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ben Attenborough
Front End Web Development Techdegree Graduate 32,769 Points

Yes that seemed to work. Perhaps the /shirts4mike/ string could be set as a variable so it only needs to be set once and can be easily changed if you move or rename the directory? Also if people are getting the internal server error it may be the .htaccess file. Try temporarily removing it and see if the site works, if it does put the file back and find the setting on your web server to allow rewrite rules. On WAMP (a Windows server) it is under Apache/Apache Modules/Rewrite_Module

Without seeing your code, it's kinda tricky! :-p

If you haven't done so already, this kind of thing should be relatively easy to debug with your best friends:

<?php

//var_dump - what the hell is in my array?
echo "Got to here";
var_dump($variable);
exit;

//echo - that well known fav.
echo "Got to here";
echo $variable;
exit;

Starting at the first process, work your way down your scripts in order of function/variables are called/created and you should be able to find what's breaking your code.

Have you checked out the lines of code you mentioned to see if the $variable has been defined previously? It may have a typo etc!

Hope this helps,

Tom

Eric Schweitzer
Eric Schweitzer
4,027 Points

Hi Tom,

Thanks for getting back. I think the problem is at a higher level. I'm getting a 500 - Internal Server Error.... but just with this class folder. Other php projects are ok. Getting these errors in my log, which I don't understand because the files it names are present at the paths given.

PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.5.12/ext/php_intl.dll' - The specified module could not be found.

[23-Aug-2014 18:21:26 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.5.12/ext/php_ldap.dll' - The specified module could not be found.

[23-Aug-2014 18:21:26 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.5.12/ext/php_intl.dll' - The specified module could not be found.

[23-Aug-2014 18:21:26 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.5.12/ext/php_ldap.dll' - The specified module could not be found.

Eric Schweitzer
Eric Schweitzer
4,027 Points

Ok. Looks like this is a known problem, from Googling it. (http://forum.wampserver.com/read.php?2,112211)

However, it perplexes me why I can run other PHP apps without incident. For example, loading this page: http://localhost/Build_a_Simple_PHP_Application/ yields a 500 - Internal Server Error, while running this page: http://localhost/CodeDynamicWebsites/26_Final/Student/ works fine. It would seem that there might be something unique to this courses files that is causing the error.

Do you have any init / htaccess files you can post that came with the project downloads? If it's specific to just this project, these files would be number one on my check list!

Eric Schweitzer
Eric Schweitzer
4,027 Points

Here's the contents of the .htaccess file:

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

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

l have having the same problem nothing at all would display in the browser?hope Treehouse can get it fixed cuz its abit frustrating Hampton Paulk Randy Hoyt . l have Randy and Hampton tagged to see if you get any answers if not would have to contact support.

Randy Hoyt, Hi, like the people above im having the same problem nothing will display when i open the project, i believe we need some help here :).

Hi Anthony Gomez l have been able to resolve this issue. its some thing to do with your .htaccess file. Check this post to fix this. You might have to run the following code on your command line to review the .htaccess file in your folder.

SUDO defaults write com.apple.Finder AppleShowAllFiles YES; killall Finder