Personal Catalogue: PHP & MySQL — Chapter 5, Exercise 1 ==================================================== TASK Add the tag checkboxes, the "New tag(s)" text input, and the show/hide JavaScript to your own add_item.php. Add a new book with two brand-new tags typed into the comma-separated field (tags that don't exist yet), then confirm both were created in tags and correctly attached in item_tags. SOLUTION With the tags-section markup, the toggleTagsSection() script, and functions.php's new get_all_tags()/find_or_create_tag()/sync_item_tags() helpers all wired into add_item.php exactly as shown in the chapter, submit the form with: Type: book Title: The Hobbit Creator: J.R.R. Tolkien New tag(s): Fantasy, Classic Fiction Since "Fantasy" and "Classic Fiction" don't exist yet in the tags table, find_or_create_tag() creates both. Confirm at the mysql> prompt: SELECT * FROM tags WHERE name IN ('Fantasy', 'Classic Fiction'); Expected output (ids will differ): +----+------------------+ | id | name | +----+------------------+ | 5 | Fantasy | | 6 | Classic Fiction | +----+------------------+ Confirm the attachment: SELECT items.title, tags.name FROM items JOIN item_tags ON item_tags.item_id = items.id JOIN tags ON tags.id = item_tags.tag_id WHERE items.title = 'The Hobbit'; Expected output: +-------------+------------------+ | title | name | +-------------+------------------+ | The Hobbit | Fantasy | | The Hobbit | Classic Fiction | +-------------+------------------+ WHY THIS WORKS AS AN ANSWER ---------------------------- It exercises the genuinely new-tag path specifically (rather than picking from an existing checkbox, which wouldn't test find_or_create_tag() at all), and verifies both halves of the real outcome — the tags rows were actually created, and the item_tags rows correctly link them to the new book — rather than just trusting the UI looked right.