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 Basic PHP Website (2018) Listing and Sorting Inventory Items Displaying All Items

Iulian Mirzac
Iulian Mirzac
3,083 Points

Illegal string offset 'img'

Hi guys,

I am trying to display elements from data.php to catalog.php. When loading the page it says: Warning: Illegal string offset 'img' in /home/treehouse/workspace/catalog.php on line 42 Warning: Illegal string offset 'title' in /home/treehouse/workspace/catalog.php on line 43

It looks as in the course but something is not right since it's not working. I have triple checked the code.

Here's the snapshot: https://w.trhou.se/24h27kkhqf

Thanks

2 Answers

Ryan S
Ryan S
27,276 Points

Hi Iulian,

The issue is that you forgot to remove the previous $catalog array that was defined a couple videos back when Alena created the "data.php" file.

In "catalog.php" you will need to remove the following lines of code near the top of your file:

$catalog = array();
$catalog[101] = "Design Patterns";
$catalog[201] = "Forrest Gump";
$catalog[301] = "Beethoven";
$catalog[102] = "Clean Code";

This array does not have the named keys that are required in your foreach loop, but the new data file does. The problem is that you are overwriting the array immediately after including it.

Iulian Mirzac
Iulian Mirzac
3,083 Points

Hi Ryan :) Awesome! Thank you a lot. It was right under my nose....