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 trialPawandeep ShopWired
Courses Plus Student 9,848 PointsParse error: syntax error, unexpected end of file in /home/treehouse/workspace/index.php on line 27
cant view the website, don't understand what I am doing wrong the code is:
<?php
include("inc/data.php");
include("inc/functions.php");
$pageTitle = "Personal Media Library";
include("inc/header.php"); ?>
<div class="section catalog random">
<div class="wrapper">
<h2>May we suggest something?</h2>
<ul class="items">
<?php
$random = array_rand($catalog,4);
var_dump($random);
foreach($random as $id) {
echo get_item_html($id,$catalog[$id]);
?>
</ul>
</div>
</div>
<?php
include("inc/footer.php");
?>
Greg Kaleka
39,021 PointsYou're missing a comma after "Books" and before "isbn".
Another tip: Always check the line before the error as well as the line the error occurred on. Often that's where the actual problem lies. PHP said "hey what's this 'isbn' thing? I was expecting a coma or a closing square bracket".
3 Answers
Greg Kaleka
39,021 PointsHi Pawandeep,
Unexpected end of file usually means you forgot to close something, and indeed - you never closed your foreach
loop. Make sure you get a }
in there . It's tricky because the line number given is just where the file ends. Just remember that this error means you opened and didn't close something somewhere.
Cheers
-Greg
Pawandeep ShopWired
Courses Plus Student 9,848 PointsI have now ensured I've closed the index.php and the same message is still coming through
but Thank you so much for your help, I shall bare that in mind next time
Greg Kaleka
39,021 PointsCan you share your updated code? It's this foreach loop that never gets closed:
foreach($random as $id) {
echo get_item_html($id,$catalog[$id]);
Pawandeep ShopWired
Courses Plus Student 9,848 Pointsnow a new message is saying **
Parse error: syntax error, unexpected '"isbn"' (T_CONSTANT_ENCAPSED_STRING), expecting ']' in /home/treehouse/workspace/inc/data.php on line 10
my updated code:
<?php
include("inc/data.php");
include("inc/functions.php");
$pageTitle = "Personal Media Library";
include("inc/header.php"); ?>
<div class="section catalog random">
<div class="wrapper">
<h2>May we suggest something?</h2>
<ul class="items">
<?php
$random = array_rand($catalog,4);
var_dump($random);
foreach($random as $id) {
echo get_item_html($id,$catalog[$id]);
}
?>
</ul>
</div>
</div>
<?php
include("inc/footer.php");
?>
}
Greg Kaleka
39,021 PointsPawandeep, your error isn't in this file - it's in data.php. See that in the error message?
Also, please try to add comments as comments, not as answers
Pawandeep ShopWired
Courses Plus Student 9,848 PointsPawandeep ShopWired
Courses Plus Student 9,848 Pointssorry, & I realised I hadn't completed the operator on Line 10 but now I have done that and here is the code, the message is still there it doesn't display nothing, can you spot anything?