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 trialShari Staten
11,540 PointsStuck on this challenge...please help.
I keep getting the error: Bummer: syntax error, unexpected '$SESSION' (T_VARIABLE) in story.php on line 9Check. What am I doing wrong?
Here's the question:
Check that each of the required session variables are not set before attempting to write the story. If the session variables are not set, redirect to play.php with the p parameter set to the first missing session variable.e question:
<?php
session_start();
if(empty(_$SESSION['word'][4])) {
header('Loction: play.php');
}
if (isset($_SESSION['word'][1] { $word1 = htmlspecialchars($_SESSION['word'][1]);}
if (isset($_SESSION['word'][2] { $word2 = htmlspecialchars($_SESSION['word'][2]);}
if (isset($_SESSION['word'][3] { $word3 = htmlspecialchars($_SESSION['word'][3]);}
if (isset($_SESSION['word'][4] { $word4 = htmlspecialchars($_SESSION['word'][4]);}
if (isset($_SESSION['word'][5] { $word5 = htmlspecialchars($_SESSION['word'][5]);}
include 'inc/header.php';
echo '<h1>My Treehouse Story</h1>';
echo '<p>There once was a(n) ' . $word1;
echo ' programmer named ' . $word2;
echo '. </p>';
echo '<p>This ' . $word3;
echo ' programmer used Treehouse to learn to ' . $word4;
echo ' the ' . $word5 . '.</p>';
echo ' <a class="btn btn-default btn-lg" href="#" role="button">Save Story</a>';
echo ' <a class="btn btn-default btn-lg" href="play.php" role="button">Play Again</a>';
echo ' <a class="btn btn-default btn-lg" href="index.php" role="button">Other Stories</a>';
include 'inc/footer.php';
1 Answer
mohamedyousfi
416 Pointsif (empty($_SESSION['word'])){
header('Location: play.php');
}
if (empty( $word1 = htmlspecialchars($_SESSION['word'][1]))){
header('Location: play.php?p=1');
}
if (empty( $word2 = htmlspecialchars($_SESSION['word'][2]))){
header('Location: play.php?p=2');
}
if (empty( $word3 = htmlspecialchars($_SESSION['word'][3]))){
header('Location: play.php?p=3');
}
if (empty( $word4 = htmlspecialchars($_SESSION['word'][4]))){
header('Location: play.php?p=4');
}
if (empty( $word5 = htmlspecialchars($_SESSION['word'][5]))){
header('Location: play.php?p=5');
}
Luc de Brouwer
Full Stack JavaScript Techdegree Student 17,939 PointsLuc de Brouwer
Full Stack JavaScript Techdegree Student 17,939 PointsHey Shari,
Take a look at how you spelled $_SESSION and how you spelled location in your header('Loction: play.php'); line.