That error means that the foreach loop was expecting to be given an array to loop through but was given something else. Whenever you're going to build an array of items that a foreach is going to work with always do:

$the_array=array();

That ensures that the variable is set up as an array, if nothing is in it the foreach will see an empty array

I'm a complete newbie at this, and I'm working off the code in the book. Would it be possible for you to rewrite the code so it'll work. If you could I'd really appreciate it and hopefully I'll be able to understand.

I'm a bit surprised that the book has this typo in it. Granted you would only see this Warning if you have PHP setup to show warnings (which is good! I prefer new users have PHP setup to show warnings and notices when learning, you'll learn better practices that way).