Managing content from admin area using PHP MySQLUsing PHP and MySQL database we will try to develop a content management solution. This is a very basic solution and more features can be added to this script. This script can be a part of any website or can be integrated to any script. This script can be used to post news, jokes, events and many other similar types of contents. Here the site admin ads or posts content from inside the admin area. The admin can select a category and then add title, date, short description and full details of the content. Let us try to learn how the admin area works. But before that let us understand how the table structures are organized in this scripts.
Tables used and there structures
Three tables are used in this script. The main table name is content. To this table admin posts the content by entering title, date, short description and long description. Here for each record one category ID is assigned. Category names are displayed in a drop down list by taking from content_cat table and only the cat_id is stored along with other data for each record in content table. Each record in content table ( after adding ) gets one unique content identification number while the record is added by using auto increment filed property. This we call cont_id and it is used for handling each record in our table.
The table content_cat is used to store category name. Each category once added by admin generates one unique category identification number and we call that cat_id. We used an auto increment field to generate this incremental unique number for each category. This category name gets linked to the content table by cat_id field. Each category name can be edited or added or delete from the content_cat table but while deleting script will check if any record is assigned to this category in main content table. If records are assigned in content table then category name will not be deleted and a message will be displayed. Same way while adding category name the script will check if that name is already existing or not.
We will be using one more table to validation the admin for entering inside the admin area. We will only store admin user id and password in this table and match with the user entered values in the login page. Please note that the password stored is not encrypted.
Here is the dump of all the three tables.
CREATE TABLE `content` (
`cont_id` int(3) NOT NULL auto_increment,
`cat_id` int(3) NOT NULL,
`dt` date NOT NULL,
`title` varchar(250) NOT NULL,
`dtl` text NOT NULL,
UNIQUE KEY `cont_id` (`cont_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
CREATE TABLE `content_admin` (
`admin_id` varchar(8) NOT NULL,
`admin_pw` varchar(8) NOT NULL,
UNIQUE KEY `admin_id` (`admin_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `content_cat` (
`cat_id` int(11) NOT NULL auto_increment,
`name` varchar(250) NOT NULL,
UNIQUE KEY `cat_id` (`cat_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
Download the full script here