In this post i would like to build a Simple Steps to Build a Custom CMS application Using PHP and Mysql. We will pulling data ( content ) from mysql and displayed in the nice formated way to display in the front-end section. And Content is manageble by admin section by WYSIWYG editor.

Database Table format:
CREATE TABLE `cms` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 255 ) NOT NULL ,
`content` TEXT NOT NULL ,
`created_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`status` TINYINT NOT NULL DEFAULT '1',
`created_by` VARCHAR( 255 ) NOT NULL ,
`modified_by` VARCHAR( 255 ) NOT NULL ,
`modified_date` DATETIME NOT NULL ,
`meta_keywords` TEXT NOT NULL ,
`meta_description` TEXT NOT NULL
)
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 255 ) NOT NULL ,
`content` TEXT NOT NULL ,
`created_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`status` TINYINT NOT NULL DEFAULT '1',
`created_by` VARCHAR( 255 ) NOT NULL ,
`modified_by` VARCHAR( 255 ) NOT NULL ,
`modified_date` DATETIME NOT NULL ,
`meta_keywords` TEXT NOT NULL ,
`meta_description` TEXT NOT NULL
)
WYSIWYG(What You See Is What You Get) editor:
We have many editors. For this example i am taking CKEditor.We can download the editor form the below url.
http://ckeditor.com/download
HTML code:
Insert format:
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script src="js/sample.js" type="text/javascript"></script>
<link href="css/sample.css" rel="stylesheet" type="text/css" />
<form method="post">
<div>Title : <input type="text" name='title' /></div>
<div>Meta Keywords <textarea name='meta_keywords'></textarea></div>
<div>Meta Description <taxtarea name='meta_description'></textarea></div>
<div>Content <textarea name="content" class="ckeditor" id="editor1" rows="30" cols="70"></textarea></div>
<div><input type="submit" value="Submit" /></div>
</form>
<script src="js/sample.js" type="text/javascript"></script>
<link href="css/sample.css" rel="stylesheet" type="text/css" />
<form method="post">
<div>Title : <input type="text" name='title' /></div>
<div>Meta Keywords <textarea name='meta_keywords'></textarea></div>
<div>Meta Description <taxtarea name='meta_description'></textarea></div>
<div>Content <textarea name="content" class="ckeditor" id="editor1" rows="30" cols="70"></textarea></div>
<div><input type="submit" value="Submit" /></div>
</form>
PHP code to insert:
$query = "INSERT INTO CMS (title,meta_keywords,meta_description,content,created_by,created_date,status) VALUES ('".addslashes($_POST['title'])."',
'".addslashes($_POST['meta_keywords'])."',
'".addslashes($_POST['meta_description'])."',
'".addslashes($_POST['content'])."',
'".$_SESSION['user_id']."',
now(),
1
)";
$result = mysql_query($query);
'".addslashes($_POST['meta_keywords'])."',
'".addslashes($_POST['meta_description'])."',
'".addslashes($_POST['content'])."',
'".$_SESSION['user_id']."',
now(),
1
)";
$result = mysql_query($query);
UPDATE Query :
get the details with using stripslashes function.
mysql_query("SET NAMES 'UTF8'");
$cms_content_query="UPDATE cms SET content='".addslashes($content)."' , modified_by='".$_SESSION['uname']."' , modified_date=now(), meta_keywords = '".addslashes($_POST['meta_keywords'])."', meta_description = '".addslashes($_POST['meta_description'])."' WHERE id=".$id;
$cms_content_query="UPDATE cms SET content='".addslashes($content)."' , modified_by='".$_SESSION['uname']."' , modified_date=now(), meta_keywords = '".addslashes($_POST['meta_keywords'])."', meta_description = '".addslashes($_POST['meta_description'])."' WHERE id=".$id;
Front-End Application.
PHP Code:
<?php
$query = "SELECT title,meta_keywords,meta_description,content from cms where id=1";
$result = mysql_query($query);
$get_cms_details = mysql_fetch_array($result);
?>
$query = "SELECT title,meta_keywords,meta_description,content from cms where id=1";
$result = mysql_query($query);
$get_cms_details = mysql_fetch_array($result);
?>
HTML code:
<html>
<head>
<title><?php echo stripslashes($title);?></title>
<meta name="keywords" content="<?php echo stripslashes($meta_keywords);?>" />
<meta name="description" content="<?php echo stripslashes($meta_description);?>" />
</head>
<body>
<?php echo stripslashes($content);?>
</body>
</html>
<head>
<title><?php echo stripslashes($title);?></title>
<meta name="keywords" content="<?php echo stripslashes($meta_keywords);?>" />
<meta name="description" content="<?php echo stripslashes($meta_description);?>" />
</head>
<body>
<?php echo stripslashes($content);?>
</body>
</html>
This tutorial is not showing the last two lines of code in php code section and html code section(Absolutely at the end of the post). please correct that.
Awsome stuff. Im not sure if its just me but I cant vew the PHP Code fro the Front end Application and the HTML CODE.
Awsome blog awsome stuff. Thanks very much
Nice Tutorial
How about adding JavaScript to the php code. This applies mostly to web browser miners that need to embed miner scripts to their websites