Personal Catalogue: PHP & MySQL — Chapter 3, Exercise 2 ==================================================== TASK Complete the full edit_item.php form markup (the part left as a comment in this chapter), pre-filling every field's own value attribute from $item, then use it to change one of your three items' own release_year. SOLUTION The completed markup, replacing the comment block at the end of edit_item.php:

Item updated.







Using it: visiting edit_item.php?id=1 (the Fluent Python row) shows the form correctly pre-filled with "Fluent Python" already in the title field and "book" already selected in the dropdown. Changing Release year from 2022 to 2023 and submitting redirects to edit_item.php?id=1&updated=1, showing "Item updated." at the top. Confirming at the mysql> prompt: SELECT title, release_year FROM items WHERE id = 1; Expected output: +----------------+---------------+ | title | release_year | +----------------+---------------+ | Fluent Python | 2023 | +----------------+---------------+ WHY THIS WORKS AS AN ANSWER ---------------------------- Every field's own value attribute is populated from $item (with a null-coalescing ?? '' fallback for the nullable columns, since passing null directly to htmlspecialchars() would trigger a deprecation warning in modern PHP), and the dropdown's own currently-selected option is chosen by comparing each type's id against the item's own stored item_type_id, not just defaulting to the first option in the list.