Okay, as a follow on from the last one, I decided to revisit the simple CMS system as I've been getting more and more enquiries about it and the files on that thread no longer exist.
I'm starting from scratch so you can ignore the previous CMS thread
I decided, I'm more likely to be interested in completing the project if it is something I will use so I have opted for creating something for one of my affiliate sites. In my example, the CMS is used for a casino and poker affiliate site but its uses stretch far beyond that.
Analysis
Okay, first of all, we ask ourselves why we need a CMS system. With the ability to edit files using a web control panel, I have enough knowledge to edit my site from any computer in the world with an Internet connection but this project is for someone else to create and publish content knowing only a small amount of HTML / Javascript etc. So the first thing I am going to do is plan the best way for this to work.
Design
I have decided that instead of doing a CMS system page by page, it would be useful to be able to reuse certain aspects of content. For example, if we take the following 3 pages and the components that make up the page:
Page 1 - All about 32 Red Casino
32 red casino review
32 red bonus scheme
32 red software
32 red promotions
As can be seen by the pages flagged with the blue star, these 'paragraphs' occur more than once so instead of duplicating the data, I want to be able to have it sit in one place and be able for it to be displayed on more than one page.
Because of this, I decided that I wanted the data to be seperate components viewable by linking pieces together to form pages, therefore my first table would be these seperate components, hereby known as 'paragraphs'.
Part one - Paragraphs
The first table contains a unique identifier (primary key), a title and the content. To create this table, run the following SQL in your database:
then, I create a simple form which accepts a title and the content and use the following MYSQL code to insert the data into a table called 'para'.
Code:
$connection = mysql_connect($host, $user, $password) or die ("can't connect".mysql_error());
$db = mysql_select_db($database, $connection) or die ("can't connect to database");
$query = "INSERT INTO para (paraTitle, paraContent) VALUES ('$paraTitle', '$paraContent')";
mysql_query($query);// or die(mysql_error());
mysql_close();
I'll post the files for this shortly. Feel free to ask questions as we go along.
Last edited by RazoRmedia; 03-14-2005 at 06:04 AM.
As he states, no mysql database is needed. For this tutorial, I am using a database but I will also try and complete the CMS use datafiles (text files) as well.
`paraId` int(11) NOT NULL auto_increment Id's won't be negative, by using UNSIGNED your length can be smaller.
`paraContent` blob Why blob, are you planning on storing Binair data?
$query = "INSERT INTO para (paraTitle, paraContent) VALUES ('$paraTitle', '$paraContent')";
Where do $paraTitle and $paraContent come from? If they come from a posted form is should be $_POST['paraContent'] and the values should be escaped (addslashes / mysql_escape_string) to prevent mysql injection.
PHP can use access and as its open source, it can run on various platforms.
I will be using PHP and a mysql database but the fundamentals are there if you wish to apply them using ASP and an access database, only the syntax will change.
PHP will run quite happily on Apache for Windows, or IIS for Windows. Apache, like PHP, is free, which is why they tend to go together - as is Linux, again, why they all go together.
The zip file attached contains the following files:
createPara.htm - This is a simple form which lets the user input a paragraph title and the paragraph content.
addParatoDB.php - This is immediately called after createPara.htm, it adds the information in the form to the database. As the paraId is autoincrement, this is never passed and instead is incremented in the DB when a new record is added.
editPara.php - retrieves all the current paragraphs and displays them together on a page with the option of choosing one to edit. This simply displays a list of all the paragraph titles and a button for the user to edit or delete the respective paragraph. The 'edit' button points at changePara.php?id=xx where 'xx' is the id of the paragraph to be edited and the delete button points at deletePara.php?id=xx where 'xx' is the id of the paragraph to be deleted.
changePara.php - this page returns the information held in the database and returns it in a form (just a couple of textboxes really. it lets you update a paragraph using a form similar to the createPara.htm page but with the chosen paragraph already in the form.
updatePara.php - this updates the changed paragraph as amended by the user in changePara.php
deletePara.php - this delete the chosen paragraph as chosen in editPara.php
The only thing missing here is the file with all the connection strings in to the database, this is needed to be added if youu wish these files to work.