6.4. Saving Page Associations

Saving the page association in your database when new entries are created requires that you modify your query in update.inc.php, as well as a couple more checks to ensure that errors don't occur.

To save the entry information, you need to:

  1. Make sure the page was specified before processing

  2. Add the page to the query to be saved

  3. Sanitize the data

  4. Use the sanitized page information to send the user back to the created entry

In update.inc.php, modify the script to include the lines highlighted in bold:

<?php

if($_SERVER['REQUEST_METHOD']=='POST'
    && $_POST['submit']=='Save Entry'
    && !empty($_POST['page']) && !empty($_POST['title']) && !empty($_POST['entry'])) { // Include database credentials and connect to the database ...

Get PHP for Absolute Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.