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 Associative Arrays

Pedro nieto Sanchez
Pedro nieto Sanchez
28,169 Points

What am I doing wrong in here?

What am I doing wrong here?

movie.php
<?php  $movie = array(
"title" => "The Empire Strikes Back"


);   ?>


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

<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>
Chris McKirgan
Chris McKirgan
5,666 Points

This executes and renders as expected to me. Can you clarify what exactly is wrong? What are you expecting? Do you get any errors?

Pedro nieto Sanchez
Pedro nieto Sanchez
28,169 Points

Yes, and also to me. But for some reason I get the message that there is an error. And I can't go forward.

Chris McKirgan
Chris McKirgan
5,666 Points

Can you please post the error you receive here? It's impossible to know what you're issue is unless you provide some more information.

Pedro nieto Sanchez
Pedro nieto Sanchez
28,169 Points

This is the error message that I am receiving.

"(X) Brummer! It looks like the title of the second movie is in the <h1>, but something else isn't quite right. Double-check the parentheses and the year."

I have also done a screenshot, is it possible to post an image here in the forum? I don't find the option to attach images.

Thanks.

Pedro nieto Sanchez
Pedro nieto Sanchez
28,169 Points

Hi I finally found it.

The problem was that i should have declared the array in this way.

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

Not the way I did.

jaja

Thanks for your time.

Chris McKirgan
Chris McKirgan
5,666 Points

Oh! What a silly evaluation by Treehouse. Glad you got your problem sorted. Its often about jigging the code around, well done on persisting :]

4 Answers

Chris McKirgan
Chris McKirgan
5,666 Points

Is it that you have the movie year not set in the variable? You have (1985) sat next to the echoed variable. Your code works, but TeamTreehouse is not validating it as it is not quite what they've asked of you.

Try removing this and setting it in the title variable:

<?php  $movie = array(
"title" => "The Empire Strikes Back (1985)"
);   
?>

<h1><?php echo $movie["title"]  ?></h1>
Pedro nieto Sanchez
Pedro nieto Sanchez
28,169 Points

Hi Chris.

I have tried that. And now I get this error message.

"Oops! It looks like Task 2 is no longer passing."

Meaning that the array it was correctly declared before.

Thanks.

Chris McKirgan
Chris McKirgan
5,666 Points

I see, perhaps the title is set correctly, but they are just expecting the echoed title to be the only thing to be output in the h1 tag ? Often with these evaluations on this site it takes a bit of experimenting. This is actually a good thing, because with developing in a commercial environment this is often the course I take for small evaluations like this.

E.g.:

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

<h1><?php echo $movie["title"]  ?></h1>
Pedro nieto Sanchez
Pedro nieto Sanchez
28,169 Points

That didn't work either.

This is the original question: "By the end of this challenge, we'll REMOVE from the page all the information about the original movie ("Back to the Future") and REPLACE it with information about the new movie ("The Empire Strikes Back"). Right now, the <h1> element has the title of the original movie as a static piece of text. Replace that with a PHP command that INSTEAD displays the title of the new movie from the array. (Be sure to leave the <h1> tags, the parentheses, and the year intact.)"

Did you manage to pass this question? Or do you think is a bug of teamtreehouse?

Thanks.

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

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

I tried this and it worked. I guess they want you to keep the date. And later when you need to replace the date, don't forget to keep the parenthesis.