In this text I will strive to describe how to develop a terribly simple Content Management System (CMS). I've chosen PHP as the server-aspect scripting language and MySQL as the database management system purely as a result of I think they are fairly simple to use and they do the work very well.
I won't spend any time describing CMSs, what they are, or why you ought to or should not use them as there are plenty of wonderful articles on this site that describe them perfectly well. I am going to just justify one approach of developing one.
This CMS consists of one internet page (index.php) that may have its contents updated by use of a normal kind (updatePage.htm). The contents entered via the shape are stored in an exceedingly database, and are accessed and displayed by the internet page. Although this CMS is just too straightforward to be of any real use, it may be used as the place to begin for a true life CMS solution. In subsequent articles I am going to study various ways in which to increase the CMS to form it more useful.
There are four files during this project:
cms.sql
updatePage.htm
updatePage.php
index.php
cms.sql
This file creates a database called cms, and creates a table in that database known as page. It also hundreds some intial data into the table. You simply want to use this file once.
updatePage.htm
This internet page contains a straightforward kind that can be used to enter the contents displayed by index.php.
updatePage.php
This is often the shape handler - the script that processes the info (entered in updatePage.htm) and inserts it into the database table (page).
index.php
This can be the internet page that displays the info held in the database table.
cms.sql
1. CREATE DATABASE cms;
2. USE cms;
3. CREATE table page (
4. pageID integer auto_increment,
5. contents text,
6. primary key (pageID)
7. );
8. insert into page (pageID, contents) values ('one', 'dummy text');
Line one creates a database called cms within the MySQL database management system.
Line a pair of tells MySQL to use the database for the next commands.
Line three creates a table within the database.
Line four creates a column known as pageID, which can contain integers, and which can be automatically incremented as new records are added to the table. As we tend to only have one internet page (index.php) in our imaginary website, we can only have one record and therefore one integer: 1. If we tend to added further pages to the table, they would be automatically numbered (a pair of, 3, 4, etc).
Line five creates a second column known as contents, that will contain text. This is often where the editable contents displayed by index.php can be stored.
Line half-dozen sets pageID as the primary key, that you'll suppose of as a reference for the table. As we have a tendency to only have one table, which can contain only one record, we tend to will not build any use of the key. I've included it though as a result of it's sensible follow to try and do so.
Line seven merely closes the little bit of code that was started in line 3.
Line eight inserts some intial knowledge into the table: one as the primary (and solely) pageID, and 'dummy text' because the contents of the first record.
updatePage.htm
(Note that for display concerns, I've inserted areas into the HTML tag names, otherwise they'd be processed as HTML code.)
1.
2.
3. Extremely Simple CMS
4.
5.
6. Extremely Easy CMS
7.
8. Enter page content:
9.
10.
11.
12.
This is just normal HTML, which most likely does not really need explaining. All it will is present a form, the contents of which are sent to updatePage.php when the 'Update Page' button is clicked.
updatePage.php
1.
This can be the shape handler, that's to say, the script that processes the data entered into the shape (in updatePage.htm).
Line 1 signifies the beginning of a PHP script.
Line two requests the contents that were posted from the form. We have a tendency to could have written $contents=$_POST['contents']; instead if we tend to had wanted to.
Line 3 connects to the MySQL database server, setting up the host name, which I've assumed to be localhost, the database user, which I've assumed to be root, and the password needed to attach to the database. I've got no plan what this is able to be for your system so I've just written the word password.
Line four updates the page table within the CMS database with the new contents.
Line 5 closes the database connection.
Line half-dozen closes the PHP script.
index.php
1.
2.
3. Home Page
4.
5. Home Page
6.
14.
15.
This is often the web page that displays the contents from the database. It's called index.php rather than index.htm because the net page contains PHP code. If the page was referred to as index.htm, the PHP preprocessor, that is half of the internet server, would not apprehend that the page contained PHP code, and would thus not attempt to process the script half of the page (lines half-dozen to thirteen). This may cause the script itself to be displayed within the browser instead of the HTML generated by the script.
Most of the lines in this web page are pretty uncomplicated and do not want explaining. Lines vi to thirteen contain the PHP script that extracts the contents from the database and displays (echos) it within the browser.
Installing/Running the CMS
To use the CMS you wish to copy the files onto your internet server into the realm allotted for internet pages. Your net server desires to support PHP and MySQL; if it does not, the CMS will not work.
You furthermore may want to use the right database connection names and passwords (those employed in the my sql connect lines within the PHP scripts).
Precisely how you run the cms.sql file to line up the database and database table can vary from internet server to internet server so it's troublesome to provide precise directions here. If you have got a phpMyAdmin icon or one thing similar in your internet server’s management/administration panel you must be ready to use that.
Once you have founded the database and table, you can simply browse to the updatePage.htm internet page and update the database contents. You can then browse to the index.php page to view the updates.
Author Resource:
Howard has been writing articles online for nearly 2 years now. Not only does this author specialize in Content Management System : CMS, you can also check out his latest website about: