Sunday, 16 August 2015

How to develop a content management system using php mysql & using ckeditor plug-ins :

23:08

Step by Step guidance to create a   CMS   System:



step 1: Now  second to   Create  Dynamic  Content  Page  from where you insert or update  record :

use following step by step:

(1)download ckeditor from   “http://ckeditor.com/download”



Now write code for   about.php  with ckeditor plugin  :
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>A Simple Page with CKEditor</title>
        <!-- Make sure the path to CKEditor is correct. -->
        <script src="ckeditor.js"></script>
    </head>
    <body>

<form action="aboutinsert.php"  method="post">
                                 
                                  Page Title<input type=text name="pagetitle"    class="form-control"><br></br>
                                 
                                  Page keyword<input type=text name="keyword"      class="form-control"><br></br>
                                 
                                  Page Description<input type=text name="description"       class="form-control"><br></br>
                                 
          <br></br>Page Content<textarea   name="editor1"   id="editor1"    rows="10" cols="80">
                write anything
            </textarea>

<script>
                // Replace the <textarea id="editor1"> with a CKEditor
                // instance, using default configuration.
                CKEDITOR.replace( 'editor1' );
            </script>

                <input  type="submit"   name="submit"  value="submit"  class="btn">
</body>
</html>




Now   write code for   “aboutinsert.php file” :
<?php

include("connect.php");

$sql="select * from about";


$result=mysql_query($sql);


$num=mysql_num_rows($result);


$pagetitle=$_POST['pagetitle'];


$keyword=$_POST['keyword'];


$description=$_POST['description'];


$editor1=$_POST['editor1'];


if($num<=0)

{

$sql="insert into about( pagetitle ,keyword  ,description ,editor1)values( '$pagetitle','$keyword','$description','$editor1')";

mysql_query($sql) or die(mysql_error());

}

else
{


 $sql1="update about set pagetitle='$pagetitle',keyword='$keyword',description='$description',editor1='$editor1'";

 mysql_query($sql1) or die(mysql_error());

}

?>

-------------------------------------------------------------------------------------------------------------------------
 Now write code for display   content   form   database to   website  about  page 
 -------------------------------------------------------------------------------------------------------------------------

Write code for    "class.php"   inside  admin  folder :

<?php

class db

{

var $host="Localhost";

var  $username="root";

var  $password="";

function connect()
{

$connect=mysql_connect($this->host,$this->username,$this->password);

mysql_select_db("cms",$connect) or die(mysql_error());

if(!$connect)
{

echo "connection error ";
}

}

function display($table)
{
$sql="select * from $table ";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
return $row;

}


}

$obj=new db();
$obj->connect();


?>





Now write code for display   content   form   database to   website  about  page  "aboutpage.php"  :
<?php
include("admin/class.php");
$table="about";
$data=$obj->display($table);  // calling display function of  class   db  code  written in class.php   file
$title=$data['pagetitle'];
$keyword=$data['keyword'];
$description=$data['description'];
$content=$data['editor1'];
?>
<html>
<head>
<title><?php    echo   $title;    ?></title>
<meta  name=keywords    content=<?php  echo $keyword;  ?>>
<meta name=description   content=<?php  echo $description;  ?>>
</head>
<body>
<?php   $content;   ?>

</body>
</html>




========================================================================
Now  just take example  for   developing   a  dynamic   category and course with  course-details:
========================================================================

Step by step code guidance:

Create table category:

create table category
(cat_id     int   primary key   auto_increment,
category    varchar(200)
);

(1)write  code for category.php  file  :

<form action="addcategory.php"   method="post">
category   name<input   type=text   name=category>
<input type=submit    name=submit   value=submit>
</form>

(2)Write   code for   addcategory.php   file :

<?php

$con=mysql_connect("localhost","root","");

mysql_select_db("vissicomp",$con);

$category=$_POST['category'];
$sql="insert into category(category)values('$category')";

mysql_query($sql);

echo  "record inserted";

?>


Step by step   guidance for  adding  course:

Create Table   course   :

create   table  course
( courseid  int primary key atuo_increment,
 coursename   varchar(200),
category        varchar(200)
);

(1) <form action=addcourse.php   method=post>

<input type=text  name=coursename>
<select name=category>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("vissicomp",$con);
$sql="select * from category";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo '<option  value="'.$row['category'].'">';
echo $row['category'];
echo '</option>';


}

?>
</select>
<input type=submit name=submit value=submit>
</form>

(2)write    code  for    addcourse.php    file :

<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("vissicomp",$con);
$coursename=$_POST['coursename'];
$category=$_POST['category'];

$sql1="select * from course where coursename='$coursename'";
$result=mysql_query($sql1);
$num=mysql_num_rows($result);
if($num>0)
{
echo "course already used use another name for course";
}
else
{
$sql="insert into course(coursename,category)values('$coursename','$category')";
$execute=mysql_query($sql);
if($execute)
{
echo "course record inserted";
}
}
?>


Step   by   step   guidance for   adding   course   Details with banner image  :



create table coursedetails
(

id  int primary key auto_increment ,
coursename  varchar(200),
title     varchar(200),
keywords varchar(200),
description varchar(200),
content     varchar(200),
image     varchar(200)
);





(1)write  code for   addcoursedetails.php  file:

<html>
<head>
 <script type="text/javascript" src="ckeditor/ckeditor.js"></script>
    </head>
<body>
<h1> add Course Details</h1>
<form action="submit1.php" method=post enctype="multipart/form-data">
<select name=coursename  >
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("vissicomp",$con);
$sql="select * from course";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo '<option  value="'.$row['coursename'].'">';
echo $row['coursename'];
echo '</option>';

}
?>
</select>
CourseTitle <input type=text  name=title>
Course Description<textarea  name="description" rows="10" cols="80">
               </textarea>
                                                   <script>
                // Replace the <textarea id="editor1"> with a CKEditor
                // instance, using default configuration.
                CKEDITOR.replace( 'description' );
            </script>
Course Banner Image :<input type=file name=image>
<input type=submit   name=submit  value=submit >
</form>
</body>
</html>

(2)now  write code for  submit1.php file:

<?php
$coursename=$_POST['coursename'];
$title=$_POST['title'];
$description=$_POST['description'];
$image=$_FILES['image']['name'];
$con=mysql_connect("localhost","root","");
mysql_select_db("vissicomp",$con);
$sql1="select * from coursedetails where coursename='$coursename'";
$result=mysql_query($sql1);
$num=mysql_num_rows($result);
if($num>0)
{
echo "course name already used use another name";
}
else
{

$sql="insert into coursedetails(coursename,title,description,image)values('$coursename','$title','$description','$image')";
move_uploaded_file($_FILES['image']['tmp_name'],"dist/images/".$_FILES['image']['name']);
$execute=mysql_query($sql);
if($execute)
{
echo "record inserted successfully";
}
}
?>


Now  write code to display category and course wise :

(1)write   code   displaycategory.php    file:

<?php
$con=mysql_connect("Localhost","root","");
mysql_select_db("vissicomp",$con);
$sql="select * from category";
$result=mysql_query($sql);
echo '<ul>';
while($row=mysql_fetch_array($result))
{

echo '<li>';
?>
<a href="selectcategory1.php?category=<?php echo $row['category'];  ?>">
<button type=submit  name=submit>
<?php
echo $row['category'];
echo '</button></a>';
echo  '<li>';
}
echo '</ul>';
?>


<?php

if(isset($_POST['submit']))
{
$catname=$_GET['category'];
$con=mysql_connect("Localhost","root","");
mysql_select_db("vissicomp",$con);
$sql="select * from course where category='$catname'";
$result=mysql_query($sql);
echo '<ul>';
while($row=mysql_fetch_array($result))
{
echo '<li>';
?>
<a href="selectcourse1.php?coursename=<?php echo $row['coursename'];  ?>">
<?php
echo $row['coursename'];
echo '</a>';
echo  '<li>';
}
echo '</ul>';

}

?>

(2)write   code    selectcourse1.php  file :

<?php

$coursename=$_GET['coursename'];

$con=mysql_connect("Localhost","root","");

mysql_select_db("vissicomp",$con);

$sql="select * from coursedetails where coursename='$coursename'";

$result=mysql_query($sql);

while($row=mysql_fetch_array($result))
{

echo $row['coursename'];

echo $row['title'];

echo $row['description'];

}

?>






























Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

1 comments:

PHP Training Mumbai, PHP MySQL Training Mumbai, PHP Course Mumbai, PHP Institute Mumbai

 

© 2013 PHP TRAINING IN MUMBAI BY OM SIR . All rights resevered. Designed by OM SIR

Back To Top