PHP Build a Basic PHP Website 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,257 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....