Deleting a Record

Prior to checking whether new data has been posted, the program checks whether the variable $_POST[‘delete’] has a value. If so, the user has clicked the DELETE RECORD button to erase a record. In this case, the value of $isbn will also have been posted.
As you’ll recall, the ISBN uniquely identifies each record. The HTML form appends the ISBN to the DELETE FROM query string created in the variable $query, which is then passed to the query method of the $conn object to issue it to MySQL.
If $_POST[‘delete’] is not set (and so there is no record to be deleted), $_POST[‘author’] and other posted values are checked. If they have all been given values, $query is set to an INSERT INTO command, followed by the five values to be inserted. The string is then passed to the query method, which upon completion returns either TRUE or FALSE. If FALSE is returned an error message is displayed, like this:

if (!$result) echo “INSERT failed”;

Leave a Reply

Your email address will not be published. Required fields are marked *