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 Browser Persistent Data with PHP Data Persistence on the Web Reading, Writing and Destroying Sessions

Jose Cardona
Jose Cardona
5,975 Points

Undefined offset

I've followed along with the video, but am not getting the same result. The last word will never populate. I ran it with a var_dump on both play and story and get the following error Notice: Undefined offset: 5 in /home/treehouse/workspace/story.php on line 7

It looks like the array has indexes 0, 1, 2, 3, 4. but I'm asking for 1, 2, 3, 4, 5 on the story.php code. The video never runs into this, and I can't figure out how to solve it with out creating other problems

Martin Park
Martin Park
12,792 Points

I think it's this bit of code in play.php that sets the array to 1,2,3,4,5.

if (isset($_POST['word'])){ $_SESSION['word'][$page-1] = filter_input(INPUT_POST, 'word', FILTER_SANITIZE_STRING); //var_dump($_SESSION);

}

Page 1 will have no word set until you go to Page 2.

When you go to Page 2, the the word from page 1 will have the index set to $page-1, which would be 1.