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

God, I'm an idiot. Please help!

I know, This is my fourth code challenge help forum post. I'm an idiot. This time, I on the associative arrays code challenge in listing inventory items which is part of build a simple php application. Here is my code:

<h1><?php echo $movie["title"]; ?> (<?php echo $movie["year"]; ?>)</h1>
<?php 

$movie = array();
$movie[title] = "The Empire Strikes Back";
$movie[year] = 1980;
$movie[director] = "Irvin Kershner";
$movie[imdb_rating] = 8.8;
$movie[imdb_ranking] = 11;

?>
<table>
<tr>
<th>Director</th>
<td>Robert Zemeckis</td>
</tr>
<tr>
<th>IMDB Rating</th>
<td>8.5</td>
</tr>
<tr>
<th>IMDB Ranking</th>
<td>53</td>
</tr>
</table>

The reason I have the other parts of the array is because I cheated a little bit and put static text into the h1 tag, and that got me through. But then I tried to fix the h1 tag later to show the php, and it made me go back to task three. the error message I get is:

Bummer! The title of the second movie is not displayed in the <h1>.

Can anyone help me?

1 Answer

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

(I'm not God, but I'll try to help. :-)

PHP code runs in order top to bottom. In the first line, you have this:

echo $movie["title"]

However, there is no $movie array defined yet. (You define it later, but it needs to be defined before you can echo it.)

Does that help?

Randy Hoyt
Randy Hoyt
Treehouse Guest Teacher

... and when you do define the array, be sure to put quotation marks around your associative keys, like this:

$movie["title"] = "The Empire Strikes Back";

Thanks for the quick response Randy! I am now passed that code challenge! (I don't know, you sure seem like god to me! :-)

This seems appropriate for the PHP God:

We are not worthy