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 Build a Simple PHP Application Listing Inventory Items Introducing Associative Arrays

Carla Thomas
seal-mask
.a{fill-rule:evenodd;}techdegree
Carla Thomas
Front End Web Development Techdegree Student 16,039 Points

Mingling PHP and HTML

I am definitely being challenged. Here's the code for the challenge:

<?php

    $movie = array();
    $movie["title"] = ("The Empire Strikes Back");
    $movie["year"] = ("1980");

?>

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

Here are the instructions for the challenge:

Right now, the <h1> element has the year of the original movie (1985) as a static piece of text. Replace that with a PHP command that INSTEAD displays the year of the new movie (1980) from the array. (Be sure to leave the parentheses intact.)

Here's my answer:

<h1><?php echo $movie["title"]; ?> 

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

Here's the error I am getting. Thanks in advance for your help.

The year of the second movie is not displayed in the &lt;h1&gt;.
Chris Southam
Chris Southam
1,823 Points

Take the brackets out from each side of both variables (title & movie)

<?php
    $movie = array();
    $movie["title"] = "The Empire Strikes Back";
    $movie["year"] = "1980";
?>

and then replace your H1 with
<h1><?php echo $movie["title"]; ?> (<?php echo $movie["year"]; ?>)</h1>

8 Answers

Chris Southam
Chris Southam
1,823 Points

I'm guessing you've got some additional spaces in your H1 tag (there is another post about this). I've done the course now and I can't see where it would be erroring for you. <h1><?php echo $movie["title"]; ?> (<?php echo $movie["year"]; ?>)</h1>

Gregory Serfaty
Gregory Serfaty
37,140 Points

i do this and it is work

<?php 
$movie = array();
$movie['title'] = "The Empire Strikes Back";
$movie['year'] = 1980;
?>

<h1><?php echo $movie['title'];?> (<?php echo $movie['year'];?>)</h1>
Carla Thomas
seal-mask
.a{fill-rule:evenodd;}techdegree
Carla Thomas
Front End Web Development Techdegree Student 16,039 Points

That is also my answer.....except the PHP must be maintained within the <h1> tags, which mine also does....do you know of another way to arrive at the answer?

Carla Thomas
seal-mask
.a{fill-rule:evenodd;}techdegree
Carla Thomas
Front End Web Development Techdegree Student 16,039 Points

Thanks Gregory. The problem turned out to be that I had extra spaces on the insides of the parenthesis ()....thank you so much for your help! :)

Chris Southam
Chris Southam
1,823 Points

Well they are the right answers when it comes to PHP but not related to what you've previously written and what Treehouse needs for the answer. I'm just going through the course myself to find the answer for you.

Gregory Serfaty
Gregory Serfaty
37,140 Points

for your array you don't need to do this ```$movie = array(); $movie["title"] = ("The Empire Strikes Back"); $movie["year"] = ("1980");

but try this 
```$movie["title"] = "The Empire Strikes Back";
    $movie["year"] = "1980";
Gregory Serfaty
Gregory Serfaty
37,140 Points

the error's message is the year is not in the h1 so just change the date in your array

Carla Thomas
seal-mask
.a{fill-rule:evenodd;}techdegree
Carla Thomas
Front End Web Development Techdegree Student 16,039 Points

That's what my coding does above while maintaining the parenthesis () as the instructions state. Please write the code so I can better understand your correction. By the way, thanks for your help.

Gregory Serfaty
Gregory Serfaty
37,140 Points

please try to delete the () in the array and put all the sentence in one ligne

Carla Thomas
seal-mask
.a{fill-rule:evenodd;}techdegree
Carla Thomas
Front End Web Development Techdegree Student 16,039 Points

When I removed the brackets from the array, I received an error stating that the previous challenge (Task 3) is no longer passing.....the challenge wants me to continue from the previous task.

Very frustrating.

Gregory Serfaty
Gregory Serfaty
37,140 Points

normal you don't want to delete the brackets but the parenthesis and put on 1 ligne

<?php echo $movie['title'];?> (<?php echo $movie['year'];?>)
Carla Thomas
seal-mask
.a{fill-rule:evenodd;}techdegree
Carla Thomas
Front End Web Development Techdegree Student 16,039 Points

Unfortunately, none of the above were the correct answer. Has anyone clicked on the link located in my original post and successfully passed (Task #4) of the challenge?

Gregory Serfaty
Gregory Serfaty
37,140 Points

i do and passed with success the answer 4 and my answer was just above

<?php $movie = array(); $movie['title'] = "The Empire Strikes Back"; $movie['year'] = 1980; ?>

<?php echo $movie['title'];?> (<?php echo $movie['year'];?>)