php · level 2 check

a guestbook stored in SQLite.

The village fete needs a guestbook on its website. Visitors send their name and a message. Your app checks each one, saves the good ones in an SQLite database, then shows the guestbook newest first, safely escaped, with a count at the top.

Each array in `$posts` stands in for one pretend `$_POST`. `clean_entry` trims and validates a form, throwing an `InvalidArgumentException` with a clear message when something is wrong. `save_entry` stores an entry using `prepare` and placeholders, and `show_entry` builds one escaped line of the guestbook.

Fill in each `____`, run it, and check every line. Then add a visitor of your own and run it again.

Fill in every ____ then run the checks.
  1. 1 A good entry is saved and shownuses: databases
  2. 2 A blank name is turned awayuses: validation
  3. 3 A short message is turned awayuses: exceptions
  4. 4 HTML in a message is escapeduses: escaping
  5. 5 Newest first, with spaces trimmeduses: SQL
  6. 6 It counts the entriesuses: formatting

Take as long as you like and try as many times as you want.