Using PHP and MySQL to Develop a Simple CMS – Version 2

In version 1 of our simple CMS we introduced the following four files:

  • cms.sql
  • updatePage.htm
  • updatePage.php, and
  • index.php

Together, these files formed a very simple CMS.

In this article we’ll extend the CMS slightly so that the database contents are extracted and presented in the form (UpdatePage.htm). This will make it easier to edit the contents, rather than simply overwriting them.

In order to make this modification, updatePage.htm needs to become a PHP file. I’ve called it editPage.php because updatePage.php already exists.

Here is the contents of editPage.php:



3. Really Simple CMS



6. Really Simple CMS



15. Enter page content:





Most of this file is fairly simple HTML that doesn’t need explaining. However, the following bits of code are probably worth discussing.

Lines 7 through to 13 contain PHP code to connect to the database and extract the contents of the web page.

Line 15 contains a tiny bit of PHP code to display the contents in the form’s textarea. This line shows how easy it is to integrate bits of PHP code into lines of HTML code.

Remember though that in order to use PHP code in an HTML page, the file has to have an extension of .php. If it does not, the PHP code will not be processed by the web server.

Although very simple, the content management system described above could be used as the basis for a more substantial, and therefore realistic, CMS.


Source link