We will make the library editable.
The previous chapter displayed books written in the controller. We will now add, correct, and delete books from the browser. Every action remains in PHP and uses PHPAML protections.
Two request types are enough to begin
Request a page or read a resource. A normal browser visit uses GET.
Send values that cause a change, such as adding a book.
GET should be repeatable without changing the library. POST expresses an intent to change. This separation makes the application predictable.
The new journey
/books/createcreate.php/books/booksAfter a successful POST, the server does not directly render the list: it asks the browser to visit /books. This POST–Redirect–GET pattern avoids creating the same book twice when the page is refreshed.
VOCABULARY
Words to remember
SUMMARY
What to remember
- GET reads; POST requests a change.
- A field name becomes the submitted key.
- Received data is never trusted by default.
- POST–Redirect–GET prevents accidental repetition.