Our application still lacks the add/edit author functionality. This page will be somewhat simpler than the edit book page because it will not have the select box for authors and no unique index. (You may want to create a unique index on the author's first and last name columns to prevent duplicates there too, but we will leave this up to you.)
Let's call this page editAuthor.php
. Here is its source code:
<?php /** * This page allows to add or edit an author * PDO Library Management example application * @author Dennis Popel */ // Don't forget the include include('common.inc.php'); // See if we have the author ID passed in the request $id = (int)$_REQUEST['author']; if($id) { // We have the ID, get the author details from the table $q = $conn->query("SELECT * FROM authors WHERE id=$id"); $author = $q->fetch(PDO::FETCH_ASSOC); $q->closeCursor(); $q = null; } else { // We are creating a new book $author = array(); } // Now see if the form was submitted...