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

carl simpson
PLUS
carl simpson
Courses Plus Student 15,941 Points

running the source code in "using php with mysql"

Hi, i am just starting the "using php with mysql" module. I have downloaded the source files from the first vid - but the index.php isn't pulling anything through, is there something i am missing? as i don't have the old t shirt store saved on my machine anymore and i'd like to do the course without having to go back and rebuild the store first

16 Answers

What is it showing?

carl simpson
PLUS
carl simpson
Courses Plus Student 15,941 Points

i downloaded the files, put them in mamp - and its just a blank screen - the code inside looks fine ie: it should work as intended but it just throws a simple 500 internal server error & nothing appears

can you write the url pls, and also are you starting mamp?

Alena Holligan
STAFF
Alena Holligan
Treehouse Teacher

Usually that the internal server error will show if the mamp servers are not running. Can you make sure you "Start Servers"

If you edit the index.php file and just type "Test" nothing else, then refresh the page what do you see?

Also, have you gone into phpMyAdmin and run the sql statements to create the database? Attached to the following video https://teamtreehouse.com/library/using-php-with-mysql/connecting-php-to-mysql/creating-the-products-table

carl simpson
PLUS
carl simpson
Courses Plus Student 15,941 Points

the database is working correctly as i have been through that stage fine . as is MAMP , i have an echo on the page to show that "something" pulls through from the index.php.

https://teamtreehouse.com/library/using-php-with-mysql/connecting-php-to-mysql/introducing-databases

i downloaded the initial project files - ran it through MAMP (which is switched on ) and it runs a blank screen

Alena Holligan
STAFF
Alena Holligan
Treehouse Teacher

Let's see if we can track down some errors :) Add the following code right below the initial <?php

error_reporting(E_ALL);
ini_set('display_errors',1);
carl simpson
PLUS
carl simpson
Courses Plus Student 15,941 Points

Hi Alena - thanks for your help .. after inserting that line of code i am now showing the following

Warning: include(/Applications/MAMP/htdocs/inc/products.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/shirts4mike/index.php on line 5

Warning: include(): Failed opening '/Applications/MAMP/htdocs/inc/products.php' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.6.2/lib/php') in /Applications/MAMP/htdocs/shirts4mike/index.php on line 5

Fatal error: Call to undefined function get_products_recent() in /Applications/MAMP/htdocs/shirts4mike/index.php on line 6

Alena Holligan
STAFF
Alena Holligan
Treehouse Teacher

looks like it's having problems including inc/products.php

can you make sure you have an "inc" folder and a "products.php" file within that folder

carl simpson
PLUS
carl simpson
Courses Plus Student 15,941 Points

the problem seems to have something to do with the ROOT_PATH .

carl simpson
PLUS
carl simpson
Courses Plus Student 15,941 Points

it seems to me like all the paths are wrong - which is why nothing shows .. if you remove the rootpath from the index- the header/products/footer pulls through basic html without styles.. the paths are coded incorrectly which is why it wont run

Alena Holligan
STAFF
Alena Holligan
Treehouse Teacher

looks like you have it in a "shirts4mike" folder there are two options.

  1. go into inc/config.php and add "shirts4mike/" to the ROOT_PATH
  2. go into index.php and remove all references to "ROOT_PATH . "

I would suggest #1

The real issue is that $_SERVER["DOCUMENT_ROOT"] is pulling what you have in MAMP > Preferences > Web Server > Document Root: Which is simply "/Applications/MAMP/htdocs/" so it is looking in "/Applications/MAMP/htdocs/inc" but you have the files in "/Applications/MAMP/htdocs/shirts4mike/inc"

carl simpson
PLUS
carl simpson
Courses Plus Student 15,941 Points

so you can only run in it in an empty htdocs folder is what your saying... ?

I can see 1/2 of whats supposed to be there but the site itself doesn't work as all the links are still borked........

Alena Holligan
STAFF
Alena Holligan
Treehouse Teacher

You can make it work in a folder by adding the folder name in 2 files

  1. inc/config.php change BASE_URL and ROOT_PATH

  2. .htaccess before all the /shirts/, one in each line

dimas aaron
dimas aaron
6,660 Points

Hi Alena, I got this kinda problem as well, how's the solution? if there any?

Thx

dimas aaron
dimas aaron
6,660 Points

Forgot something, the folder is already in there MAMP>htdocs. but I can't find any files in the folder in my localhost, just blank.

Thx

Alena Holligan
Alena Holligan
Treehouse Teacher

dimas aaron

Place the files you download in the MAMP>htdocs folder, then IF YOU NEED TO adding the folder name in 2 files

inc/config.php change BASE_URL and ROOT_PATH

.htaccess before all the /shirts/, one in each line