In: PHP
11 Nov 2009In this tutorial I am going to show you how you can develop a simple CMS (Content Management System) in a very quick and easy way. In this tutorial I have used table for layout. You can use your CSS style for develop your CMS.
Let’s begain with Database.
Create Database CMS for your CMS site
Copy and paste the following query to create quick tables. Or you can create your own as you wish.
CREATE TABLE `siteconfig` (
`id` int(11) NOT NULL auto_increment,
`cmstitle` varchar(200) collate latin1_general_ci NOT NULL,
`version` varchar(50) collate latin1_general_ci NOT NULL,
`copyinfo` varchar(200) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM
INSERT INTO `siteconfig` (`id`, `cmstitle`, `version`, `copyinfo`) VALUES
(1, 'Jagadishwor''s Simple CMS System', 'Version 1.0', 'Copyright © <a href="http://www.jagadishwor.com.np">Jagadishwor.com.np</a> 2009');
CREATE TABLE `tblcategory` (
`catid` int(11) NOT NULL auto_increment,
`catname` varchar(100) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`catid`)
) ENGINE=MyISAM
INSERT INTO `tblcategory` (`catid`, `catname`) VALUES
(1, 'AJAX'),
(3, 'MYSQL'),
(4, 'Wordpress'),
(5, 'CSS');
CREATE TABLE `tblpost` (
`postid` int(11) NOT NULL auto_increment,
`heading` varchar(250) collate latin1_general_ci NOT NULL,
`article` longtext collate latin1_general_ci NOT NULL,
`postdate` date NOT NULL,
`postby` varchar(200) collate latin1_general_ci NOT NULL,
`catid` int(11) NOT NULL,
`posttag` varchar(100) collate latin1_general_ci NOT NULL,
`status` int(1) NOT NULL,
PRIMARY KEY (`postid`)
) ENGINE=MyISAM
Now We will start to develop our Content Management System

Before we start we will discuss about the layout and pages.
In this tutorial I am going to develop pages like this:
header.php
menu.php
archieves.php
index.php
footer.php
sidebar.php
category.php
result.php
article.php
style.css
include/constr.php
include/definer.php
Create a database connection string inside include folder:
<?php
$db_host = "localhost";
$db_user = "root";//Change to your mysql user
$db_pass = ""; // Change to your mysql password
$db_name = "cms";
mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name);
?>
Now I am going to define some value for our CMS like title, copyinfo and version in definer. I will update it in my comming system. Create definer.php inside your include folder and paste the code:
<?php
$query='SELECT * from siteconfig';
$result=mysql_query($query);
if(!$result){
die('No Title Found For This Page because '. mysql_error());
}else{
$row=mysql_fetch_array($result);
$title=$row['cmstitle'];
$version=$row['version'];
$copyright=$row['copyinfo'];
}
?>
Create a new php file name it index.php and save it in your root.
<?php include 'header.php';?>
<tr>
<td colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="dispaly">
<tr>
<td><table width="96%" border="0" cellspacing="0" cellpadding="0" align="center">
<?php
$rowsPerPage = 7;
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
$qry="SELECT a.*, b.catname FROM `tblpost` a, `tblcategory` b WHERE a.catid=b.catid ORDER BY a.postid DESC LIMIT $offset, $rowsPerPage";
$result=mysql_query($qry);
while($row=mysql_fetch_array($result)){
?>
<tr>
<td><h1><a href="article.php?id=<?php echo $row['postid'];?>"><?php echo $row['heading'];?></a><span> »<?php echo $row['postdate'];?></span></h1></td>
</tr>
<tr>
<td><span class="posted"><strong>Posted By: </strong><em><?php echo $row['postby'];?></em> »<strong>Under Category: </strong><em><?php echo $row['catname'];?></em> »<strong>Under Tag: </strong><em><?php echo $row['posttag'];?></em></span></td>
</tr>
<tr>
<td><?php echo substr(str_replace("\r\n","<br>",$row['article']),0,400)." <a href='article.php?id=$row[postid]'>Read More...</a>";?></td>
</tr>
<tr>
<td></td>
</tr>
<?php
}
?>
<tr>
<td><center>
<?php
$query = "SELECT COUNT(postid) AS numrows FROM tblpost";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"$self?action=view-news&page=$page\">$page</a> ";
}
}
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?action=view-news&page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?action=view-news&page=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?action=view-news&page=$page\">[Next]</a> ";
$last = " <a href=\"$self?action=view-news&page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $prev . $nav . $next."<br>";
echo "Page $pageNum of $maxPage";
// and close the database connection
?></center>
</td>
</tr>
</table></td>
</tr>
</table></td>
<td width="24%" bgcolor="#8c8c8c" valign="top" align="center"><?php include 'sidebar.php';?></td>
</tr>
<?php include 'footer.php';?>
</table></td>
</tr>
</table>
</body>
</html>
Paste code for your header.php file under your root folder.
<?php include 'include/constr.php';?>
<?php include 'include/definer.php';?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo $title;?></title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#464646">
<td height="90" colspan="3"><span class="sitetitle"><?php echo $title;?></span></td>
</tr>
<tr>
<td colspan="3"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="76%" height="35"><span class="menu"><?php echo $home="<a href='index.php'> Home </a> | ";?><?php include 'menu.php';?></span></td>
<td width="24%" valign="middle"><form name="form1" method="post" action="result.php">
Search
<input name="search" type="text" id="search" size="20">
<input type="submit" name="Submit" value="Go">
</form></td>
</tr>
</table></td>
</tr>
Create footer.php in the same location
<tr>
<td colspan="3"> </td>
</tr>
<tr bgcolor="#6d6d6d">
<td width="33%" height="40"><span class="footertext"><?php echo $copyright;?></span></td>
<td width="43%"> </td>
<td><span class="footertext"><em><?php echo $version;?></em></span></td>
</tr>
Create sidebar.php in the root directory and paste code
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" bgcolor="#4d4d4d"><span class="archtitle">Archieve</span></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php
$query="SELECT MONTH(postdate) MONTH, MONTHNAME(postdate)MONTHNAME, YEAR(postdate)year FROM tblpost GROUP BY MONTH(postdate) , YEAR(postdate) ORDER BY postdate";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF" height="2px"></td>
</tr>
<tr>
<td height="20"><span class="menupost"><a href="archieves.php?month=<?php echo $row['MONTH'];?>&year=<?php echo $row['year'];?>"><?php echo $row['MONTHNAME']."-". $row['year'];?></a></span></td>
</tr>
<?php
}
?>
</table></td>
</tr>
<tr>
<td height="30" bgcolor="#4d4d4d"><span class="archtitle">Recent Post</span></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td></td>
</tr>
<?php
$query="SELECT postid, heading, article FROM tblpost ORDER BY postid DESC LIMIT 0,10";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF" height="2px"></td>
</tr>
<tr>
<td align="left"><span class="menupost">» <a href="article.php?id=<?php echo $row['postid'];?>"><strong><?php echo $row['heading'];?>: </strong><?php echo substr($row['article'], 0, 40)." ...";?></a></span></td>
</tr>
<?php
}
?>
</table></td>
</tr>
</table>
To display menu create menu.php in your root and paste the code
<?php
$qry="SELECT * FROM tblcategory ORDER BY catid ASC";
$result=mysql_query($qry);
while($row=mysql_fetch_array($result)){
echo "<a href='category.php?catid=$row[catid]'>".$row['catname']."</a>". " | ";
}
?>
We complete our index page and now you can test your index page. For more option we will develop four more pages which will display content on the basis of articles (Full article), archieves, search result and category.
Now first create article.php page and paste the following code
<?php include 'header.php';?>
<tr>
<td colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="dispaly">
<tr>
<td><table width="96%" border="0" cellspacing="0" cellpadding="0" align="center">
<?php
if(isset($_GET['id'])){
$id=$_GET['id'];
if($id!=""){
$qry="SELECT a.*, b.catname FROM `tblpost` a, `tblcategory` b WHERE a.catid=b.catid and a.postid='$id'";
$result=mysql_query($qry);
if(mysql_num_rows($result)<1){
echo "Sorry No post found!";
}
while($row=mysql_fetch_array($result)){
?>
<tr>
<td><h1><a href="article.php?id=<?php echo $row['postid'];?>"><?php echo $row['heading'];?></a><span> »<?php echo $row['postdate'];?></span></h1></td>
</tr>
<tr>
<td><span class="posted"><strong>Posted By: </strong><em><?php echo $row['postby'];?></em> »<strong>Under Category: </strong><em><?php echo $row['catname'];?></em> »<strong>Under Tag: </strong><em><?php echo $row['posttag'];?></em></span></td>
</tr>
<tr>
<td><?php echo str_replace("\r\n","<br>",$row['article']);?></td>
</tr>
<tr>
<td></td>
</tr>
<?php
}
?>
<tr>
<td>
<?php
}
}
?>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table></td>
</tr>
</table></td>
<td width="24%" bgcolor="#8c8c8c" valign="top" align="center"><?php include 'sidebar.php';?></td>
</tr>
<?php include 'footer.php';?>
</table></td>
</tr>
</table>
</body>
</html>
Create category.php page and paste code
<?php include 'header.php';?>
<tr>
<td colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="dispaly">
<tr>
<td><table width="96%" border="0" cellspacing="0" cellpadding="0" align="center">
<?php
$catid=$_GET['catid'];
$rowsPerPage = 7;
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
$qry="SELECT a.*, b.catname FROM `tblpost` a, `tblcategory` b WHERE a.catid=b.catid and a.catid='$catid' ORDER BY a.postid DESC LIMIT $offset, $rowsPerPage";
$result=mysql_query($qry);
if(mysql_num_rows($result)<1){
echo "Sorry No post found!";
}
while($row=mysql_fetch_array($result)){
?>
<tr>
<td><h1><a href="article.php?id=<?php echo $row['postid'];?>"><?php echo $row['heading'];?></a><span> »<?php echo $row['postdate'];?></span></h1></td>
</tr>
<tr>
<td><span class="posted"><strong>Posted By: </strong><em><?php echo $row['postby'];?></em> »<strong>Under Category: </strong><em><?php echo $row['catname'];?></em> »<strong>Under Tag: </strong><em><?php echo $row['posttag'];?></em></span></td>
</tr>
<tr>
<td><?php echo substr(str_replace("\r\n","<br>",$row['article']),0,400)." <a href='article.php?id=$row[postid]'>Read More...</a>";?></td>
</tr>
<tr>
<td></td>
</tr>
<?php
}
?>
<tr>
<td><center>
<?php
$query = "SELECT COUNT(postid) AS numrows FROM tblpost";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"$self?action=view-news&page=$page\">$page</a> ";
}
}
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?action=view-news&page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?action=view-news&page=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?action=view-news&page=$page\">[Next]</a> ";
$last = " <a href=\"$self?action=view-news&page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $prev . $nav . $next."<br>";
echo "Page $pageNum of $maxPage";
// and close the database connection
?></center>
</td>
</tr>
</table></td>
</tr>
</table></td>
<td width="24%" bgcolor="#8c8c8c" valign="top" align="center"><?php include 'sidebar.php';?></td>
</tr>
<?php include 'footer.php';?>
</table></td>
</tr>
</table>
</body>
</html>
Now create archieves.php page to show archieve list.
<?php include 'header.php';?>
<tr>
<td colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="dispaly">
<tr>
<td><table width="96%" border="0" cellspacing="0" cellpadding="0" align="center">
<?php
$month=$_GET['month'];
$year=$_GET['year'];
$date=$year."-".$month;
$rowsPerPage = 7;
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
$qry="SELECT a.*, b.catname FROM `tblpost` a, `tblcategory` b WHERE a.catid=b.catid and MONTH(a.postdate)='$month' and YEAR(a.postdate)='$year' ORDER BY a.postdate DESC LIMIT $offset, $rowsPerPage";
$result=mysql_query($qry);
if(mysql_num_rows($result)<1){
echo "Sorry No post found!";
}
while($row=mysql_fetch_array($result)){
?>
<tr>
<td><h1><a href="article.php?id=<?php echo $row['postid'];?>"><?php echo $row['heading'];?></a><span> »<?php echo $row['postdate'];?></span></h1></td>
</tr>
<tr>
<td><span class="posted"><strong>Posted By: </strong><em><?php echo $row['postby'];?></em> »<strong>Under Category: </strong><em><?php echo $row['catname'];?></em> »<strong>Under Tag: </strong><em><?php echo $row['posttag'];?></em></span></td>
</tr>
<tr>
<td><?php echo substr(str_replace("\r\n","<br>",$row['article']),0,400)." <a href='article.php?id=$row[postid]'>Read More...</a>";?></td>
</tr>
<tr>
<td></td>
</tr>
<?php
}
?>
<tr>
<td><center>
<?php
$query = "SELECT COUNT(postid) AS numrows FROM tblpost";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"$self?action=view-news&page=$page\">$page</a> ";
}
}
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?action=view-news&page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?action=view-news&page=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?action=view-news&page=$page\">[Next]</a> ";
$last = " <a href=\"$self?action=view-news&page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $prev . $nav . $next."<br>";
echo "Page $pageNum of $maxPage";
// and close the database connection
?></center>
</td>
</tr>
</table></td>
</tr>
</table></td>
<td width="24%" bgcolor="#8c8c8c" valign="top" align="center"><?php include 'sidebar.php';?></td>
</tr>
<?php include 'footer.php';?>
</table></td>
</tr>
</table>
</body>
</html>
Now create page for search result, result.php
<?php include 'header.php';?>
<tr>
<td colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="dispaly">
<tr>
<td><table width="96%" border="0" cellspacing="0" cellpadding="0" align="center">
<?php
if(isset($_POST['search'])){
$search=$_POST['search'];
}
$rowsPerPage = 7;
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
$qry="SELECT * FROM `tblpost` WHERE heading like '%$search%' or posttag like '%$search%'ORDER BY postid DESC LIMIT $offset, $rowsPerPage";
$result=mysql_query($qry);
if(mysql_num_rows($result)<1){
echo "Sorry No post found for your search!";
}
while($row=mysql_fetch_array($result)){
?>
<tr>
<td><h1><a href="article.php?id=<?php echo $row['postid'];?>"><?php echo $row['heading'];?></a><span> »<?php echo $row['postdate'];?></span></h1></td>
</tr>
<tr>
<td><span class="posted"><strong>Posted By: </strong><em><?php echo $row['postby'];?></em> »<strong>Under Category: </strong><em><?php
$sql="SELECT catname from tblcategory WHERE catid=$row[catid]";
$res=mysql_query($sql);
$rowcat=mysql_fetch_array($res);
$catname=$rowcat['catname'];
echo $catname;
?></em> »<strong>Under Tag: </strong><em><?php echo $row['posttag'];?></em></span></td>
</tr>
<tr>
<td><?php echo substr(str_replace("\r\n","<br>",$row['article']),0,400)." <a href='article.php?id=$row[postid]'>Read More...</a>";?></td>
</tr>
<tr>
<td></td>
</tr>
<?php
}
?>
<tr>
<td><center>
<?php
$query = "SELECT COUNT(postid) AS numrows FROM tblpost";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"$self?action=view-news&page=$page\">$page</a> ";
}
}
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?action=view-news&page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?action=view-news&page=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?action=view-news&page=$page\">[Next]</a> ";
$last = " <a href=\"$self?action=view-news&page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $prev . $nav . $next."<br>";
echo "Page $pageNum of $maxPage";
// and close the database connection
?></center>
</td>
</tr>
</table></td>
</tr>
</table></td>
<td width="24%" bgcolor="#8c8c8c" valign="top" align="center"><?php include 'sidebar.php';?></td>
</tr>
<?php include 'footer.php';?>
</table></td>
</tr>
</table>
</body>
</html>
OK our CMS for client side have been completed. Now create admin section for post articles and add category. Create folder admin in your root.

Now create a index.php file inside your root and paste the following code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Jagadishwor's Simple CMS System</title>
<link href="../style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#464646">
<td height="90" colspan="2" bgcolor="#464646"><span class="sitetitle">Jagadishwor's Simple CMS System</span></td>
<td height="90"> </td>
</tr>
<tr>
<td colspan="3"> </td>
</tr> <tr>
<td colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="dispaly">
<tr>
<td><form name="form1" method="post" action="">
<table width="96%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><h1><a href="article.php?id=1">Welcome admin Please click on the menu for your work. </a><span> </span></h1></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><center>
</center></td>
</tr>
</table>
</form></td>
</tr>
</table></td>
<td width="24%" bgcolor="#8c8c8c" valign="top" align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" bgcolor="#4d4d4d"><span class="archtitle">Admin Menu </span></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF" height="2px"></td>
</tr>
<tr>
<td height="20"><span class="menupost"><a href="addnew.php">Add New Post </a></span></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="20"><a href="viewpost.php" class="menupost">View Post </a></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="20"><a href="addcategory.php" class="menupost">Add New Category </a></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="30" bgcolor="#4d4d4d"> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" height="2px"></td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr bgcolor="#6d6d6d">
<td width="33%" height="40"><span class="footertext">Copyright © <a href="http://www.jagadishwor.com.np">Jagadishwor.com.np</a> 2009</span></td>
<td width="43%"> </td>
<td><span class="footertext"><em>Version 1.0</em></span></td>
</tr> </table></td>
</tr>
</table>
</body>
</html>
To add New post contents let’s add a new file addnew.php
<?php include '../include/constr.php';?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Jagadishwor's Simple CMS System</title>
<link href="../style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#464646">
<td height="90" colspan="2" bgcolor="#464646"><span class="sitetitle">Jagadishwor's Simple CMS System</span></td>
<td height="90"> </td>
</tr>
<tr>
<td colspan="3"> </td>
</tr> <tr>
<td colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="dispaly">
<tr>
<td><form name="form1" method="post" action="">
<table width="96%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><h1><a href="article.php?id=1">Welcome admin Please click on the menu for your work. </a><span> </span></h1></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td><div align="right"><strong>Post Title </strong></div></td>
<td><input name="title" type="text" id="title" size="40"></td>
<td> </td>
</tr>
<tr>
<td><div align="right"><strong>Post Contents </strong></div></td>
<td><textarea name="contents" cols="40" rows="10" id="contents"></textarea></td>
<td> </td>
</tr>
<tr>
<td><div align="right"><strong>Category</strong></div></td>
<td><?php
$result = mysql_query("SELECT * FROM tblcategory");
echo "<select name=\"catg\" id=\"catg\">";
while($row2 = mysql_fetch_array($result))
{
echo "<option value=" . $row2['catid'] .">".$row2['catname'];
echo " </option>";
}
echo "</select>";
?></td>
<td> </td>
</tr>
<tr>
<td><div align="right"><strong>Post By </strong></div></td>
<td><input name="postby" type="text" id="postby"></td>
<td> </td>
</tr>
<tr>
<td><div align="right"><strong>Post Tags </strong></div></td>
<td><input name="tags" type="text" id="tags"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input name="addpost" type="submit" id="addpost" value="Add Post"></td>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><center>
</center></td>
</tr>
</table>
</form></td>
</tr>
</table></td>
<td width="24%" bgcolor="#8c8c8c" valign="top" align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" bgcolor="#4d4d4d"><span class="archtitle">Admin Menu </span></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF" height="2px"></td>
</tr>
<tr>
<td height="20"><span class="menupost"><a href="addnew.php">Add New Post </a></span></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="20"><a href="viewpost.php" class="menupost">View Post </a></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="20"><a href="addcategory.php" class="menupost">Add New Category </a></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="30" bgcolor="#4d4d4d"> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" height="2px"></td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr bgcolor="#6d6d6d">
<td width="33%" height="40"><span class="footertext">Copyright © <a href="http://www.jagadishwor.com.np">Jagadishwor.com.np</a> 2009</span></td>
<td width="43%"> </td>
<td><span class="footertext"><em>Version 1.0</em></span></td>
</tr> </table></td>
</tr>
</table>
<?php
if(isset($_POST['addpost'])){
$title=$_POST['title'];
$contents=$_POST['contents'];
$category=$_POST['catg'];
$postby=$_POST['postby'];
$today=date("Y-m-d");
$posttags=$_POST['tags'];
}
if(($title<>"") and ($contents<>"") and ($category<>"")){
$qry="INSERT into tblpost (heading, article, postdate, postby, catid, posttag, status) VALUES ('$title', '$contents', '$today', '$postby', '$category', '$posttag', '1')";
$result=mysql_query($qry);
if($result){
?>
<script>
alert("New Post added Successfully")
window.location("addnew.php");
</script>
<?php
}else{
echo "Can not add your post.";
}
}
?>
</body>
</html>
To view and delete your post create new file viewpost.php
<?php include '../include/constr.php';?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Jagadishwor's Simple CMS System</title>
<link href="../style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#464646">
<td height="90" colspan="2" bgcolor="#464646"><span class="sitetitle">Jagadishwor's Simple CMS System</span></td>
<td height="90"> </td>
</tr>
<tr>
<td colspan="3"> </td>
</tr> <tr>
<td colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="dispaly">
<tr>
<td><form name="form1" method="post" action="">
<table width="96%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><h1><a href="article.php?id=1">Welcome admin Please click on the menu for your work. </a><span> </span></h1></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td><div align="center"><strong>SNO</strong></div></td>
<td><div align="center"><strong>Title</strong></div></td>
<td><div align="center"><strong>Post Date </strong></div></td>
<td><div align="center"><strong>Category</strong></div></td>
<td><div align="center"><strong>Post By </strong></div></td>
<td><div align="center"><strong>Action</strong></div></td>
</tr>
<?php
$qry="SELECT a.*, b.catname FROM `tblpost` a, `tblcategory` b WHERE a.catid=b.catid ORDER BY a.postid DESC";
$result=mysql_query($qry);
$sno=1;
while($row=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $sno;?></td>
<td><?php echo $row['heading'];?></td>
<td><?php echo $row['postdate'];?></td>
<td><?php echo $row['catname'];?></td>
<td><?php echo $row['postby'];?></td>
<td><a href="viewpost.php?action=delete&id=<?php echo $row['postid'];?>">Delete</a></td>
</tr>
<?php
$sno=$sno+1;
}
?>
</table></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</form></td>
</tr>
</table></td>
<td width="24%" bgcolor="#8c8c8c" valign="top" align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" bgcolor="#4d4d4d"><span class="archtitle">Admin Menu </span></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF" height="2px"></td>
</tr>
<tr>
<td height="20"><span class="menupost"><a href="addnew.php">Add New Post </a></span></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="20"><a href="viewpost.php" class="menupost">View Post </a></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="20"><a href="addcategory.php" class="menupost">Add New Category </a></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="30" bgcolor="#4d4d4d"> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" height="2px"></td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr bgcolor="#6d6d6d">
<td width="33%" height="40"><span class="footertext">Copyright © <a href="http://www.jagadishwor.com.np">Jagadishwor.com.np</a> 2009</span></td>
<td width="43%"> </td>
<td><span class="footertext"><em>Version 1.0</em></span></td>
</tr> </table></td>
</tr>
</table>
<?php
if(isset($_GET['action'])){
$id=$_GET['id'];
if($id<>""){
$sql="DELETE FROM tblcategory WHERE catid='$id'";
echo $sql;
$result=mysql_query($sql);
if($result){
?>
<script>
alert("Article Deleted.")
window.location=("viewpost.php");
</script>
<?php
}
}
}
?>
</body>
</html>
OK finally to add category create page addcategory.php
<?php include '../include/constr.php';?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Jagadishwor's Simple CMS System</title>
<link href="../style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#464646">
<td height="90" colspan="2" bgcolor="#464646"><span class="sitetitle">Jagadishwor's Simple CMS System</span></td>
<td height="90"> </td>
</tr>
<tr>
<td colspan="3"> </td>
</tr> <tr>
<td colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="dispaly">
<tr>
<td><form name="form1" method="post" action="">
<table width="96%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><h1><a href="article.php?id=1">Welcome admin Please click on the menu for your work. </a><span> </span></h1></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td><div align="right"><strong>Category Name </strong></div></td>
<td><input name="catname" type="text" id="catname" size="40"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input name="addcategory" type="submit" id="addcategory" value="Add New Category"></td>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><center>
</center></td>
</tr>
</table>
</form></td>
</tr>
</table></td>
<td width="24%" bgcolor="#8c8c8c" valign="top" align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" bgcolor="#4d4d4d"><span class="archtitle">Admin Menu </span></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF" height="2px"></td>
</tr>
<tr>
<td height="20"><span class="menupost"><a href="addnew.php">Add New Post </a></span></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="20"><a href="viewpost.php" class="menupost">View Post </a></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="20"><a href="addcategory.php" class="menupost">Add New Category </a></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
<tr>
<td height="2" bgcolor="#ffffff"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="30" bgcolor="#4d4d4d"> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" height="2px"></td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr bgcolor="#6d6d6d">
<td width="33%" height="40"><span class="footertext">Copyright © <a href="http://www.jagadishwor.com.np">Jagadishwor.com.np</a> 2009</span></td>
<td width="43%"> </td>
<td><span class="footertext"><em>Version 1.0</em></span></td>
</tr> </table></td>
</tr>
</table>
<?php
if(isset($_POST['addcategory'])){
$catg=$_POST['catname'];
}
if($catg<>""){
$sql="INSERT into tblcategory (catid, catname) values(NULL, '$catg')";
$result=mysql_query($sql) or die('Can not Add New Category');
if($result){
echo "Category Added. Returning Back. Please Wait";
?>
<script>
alert("Category added returning to back")
window.location=("addcategory.php");
</script>
<?php
}
}
?>
</body>
</html>
Wow! you complete your CMS system. I hope you understand all my codes. It’s very easy way to develop CMS System using php and mysql. I am developing a CMS system which will be online for all my readers who want their own CMS system very soon.

3 Responses to PHP Mysql own CMS system Tutorial
Kouba
November 27th, 2009 at 11:01 pm
Very interesting and amusing subject. I read with great pleasure.
Logan
December 12th, 2009 at 7:01 am
Hy! very interesting
really like it, but you didn’t post the style.css source
it will be very helpful if you’ll make an archive with all the files in it
have a great day
admin
December 14th, 2009 at 12:13 am
@Logan: Ok I will post it soon.