HOME      |      HTML      |      PHP      |      DREAMWEAVER      |      CSS      |      C      |

Administration panel Tutorial for Complete CMS

administration.php

<?php
require_once 'db_connect.php';
session_start();
if(!$_SESSION['name'])
{
header("Location:login.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="admin_style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="container">
<div id="header">
<div align="center">
<h1>ADMINISTRATION PANEL</h1>
</div>
</div>
<div id="menu">
<strong>Welcome :</strong> <?php echo $_SESSION['name']; ?>&nbsp;&nbsp;
<a href="logout.php" target="_self">Logout</a></div>
<div id="column1">
<p><a href="theme.php" target="_self">Change Theme</a></p>
<p><strong>Category</strong>_________________________________</p>
<p><a href="category.php" target="_self">Create New</a></p>
<p><a href="category_remove.php" target="_self">Remove</a></p>
<p><strong>Article Manipulation _</strong>______________________</p>
<p><a href="new_page.php" target="_self">Create New</a></p>
<a href=administration.php?id=viewall>View all </a><br/><br/>
<b>Category Wise</b>
<br/>
<?php
$qry=mysql_query("SELECT * FROM category", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}

/* Fetching data from the field "title" */
while($row=mysql_fetch_array($qry))
{
echo "<li><a href=administration.php?cat=".$row['category'].">".$row['category']."</a></li>";
}
?>
<p><strong>Home Page</strong> _______________________________</p>
<p><a href="primary_page.php" target="_self">Create Primary Pages</a> (eg:-about us, contact us etc)</p>
<a href=administration.php?home=index>Index Page(Home) </a><br/>
<a href=administration.php?index=viewall>Primary Pages </a><br/><br/>
<p>&nbsp;</p>
</div>
<div id="column2">
<?php
if(isset($_GET['id'])=="viewall")
{
$qry=mysql_query("SELECT * FROM category_pages order by category_pages.id DESC ", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
echo "<table>";
/* Fetching data from the field "title" */
while($row=mysql_fetch_array($qry))
{
echo "<tr>";
echo "<td><a href=pages.php?id=".$row['pg_name'].">".$row['hyperlink_name']."</a></td>";
echo "<td><a href=edit_page.php?id=".$row['id'].">edit</a></td>";
echo "<td><a href=delete.php?id=".$row['id'].">delete</a></td>";
echo "</tr>";
}
echo "</table>";
}
?>

<?php
if(isset($_GET['cat']))
{
$cat=$_GET['cat'];


$qry=mysql_query("SELECT * FROM category_pages WHERE category='$cat' order by category_pages.id DESC", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
echo "<table>";
while($row=mysql_fetch_array($qry))
{
//echo $row['title'];
echo "<tr>";
echo "<td><a href=pages.php?id=".$row['pg_name'].">".$row['hyperlink_name']."</a></td>";
echo "<td><a href=edit_page.php?id=".$row['id'].">edit</a></td>";
echo "<td><a href=delete.php?id=".$row['id'].">delete</a></td>";
echo "</tr>";
}
echo "</table>";
}
?>
<?php
if(isset($_GET['index'])=="viewall")
{
$qry=mysql_query("SELECT * FROM home_page WHERE pg_type='menu' order by home_page.id DESC ", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
echo "<table>";
/* Fetching data from the field "title" */
while($row=mysql_fetch_array($qry))
{
echo "<tr>";
echo "<td><a href=index.php?page=".$row['pg_name'].">".$row['hyperlink_name']."</a></td>";
echo "<td><a href=edit_primary.php?id=".$row['id'].">edit</a></td>";
echo "<td><a href=delete.php?page=".$row['id'].">delete</a></td>";
echo "</tr>";
}
echo "</table>";
}
?>

<?php
if(isset($_GET['home'])=="index")
{
$qry=mysql_query("SELECT * FROM home_page WHERE pg_type='content'  ", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
echo "<table>";
/* Fetching data from the field "title" */
while($row=mysql_fetch_array($qry))
{
echo "<tr>";
echo "<td><a href=index.php?page=".$row['pg_name'].">".$row['pg_name']."</a></td>";
echo "<td><a href=edit_primary.php?id=".$row['id'].">edit</a></td>";
echo "</tr>";
}
echo "</table>";
}
?>
</div>
</div>
<?php mysql_close($con); ?>
</body>
</html>

Connection to database is established by calling db_connect.php

require_once 'db_connect.php';

Session is started using,

session_start();

A conditional statement is used to verify whether the $_SESSION[‘name’] is set. If it is not set the control is transferred back to login.php

if(!$_SESSION['name'])
{
header("Location:login.php");
}

When the administrator login in Admin Panel. Administrator is welcomed by displaying his name. This is achieved using the following statement.

<strong>Welcome :</strong> <?php echo $_SESSION['name']; ?>

There is also a hyperlink named “Logout” which when clicked will transfer the control to logout.php.

<a href="logout.php" target="_self">Logout</a>

A hyperlink “Change theme is placed, which when clicked will transfer the control to theme.php.

<a href="theme.php" target="_self">Change Theme</a>

Under the section category a hyperlink “Create new” is placed, which when clicked will transfer the control to category.php

<p><a href="category.php" target="_self">Create New</a></p>

Also a hyperlink “Remove” is placed which when clicked, will transfer the control to category_remove.php

<p><a href="category_remove.php" target="_self">Remove</a></p>

Under the section “Article Manipulation”, “Create New” hyperlink is placed, which when clicked will transfer the control to new_page.php.

<p><a href="new_page.php" target="_self">Create New</a></p>

Also there is a hyperlink “View All” which when clicked will pass a value “viewall” through the url variable “id” to the administration.php page itself.

<a href=administration.php?id=viewall>View all </a><br/><br/>

Next step is to display the list of all available categories, which when clicked should display all the articles corresponding to them.

To achieve this, mysql_query() is used to query all the existing categories from the database table “category”.

if(!$qry)
{
die("Query Failed: ". mysql_error());
}

Then mysql_fetch_array() is used to display the category names as hyperlink. When the hyperlink is clicked, the category name is transferred to administration.php file itself through the url variable “cat”.

while($row=mysql_fetch_array($qry))
{
echo "<li><a href=administration.php?cat=".$row['category'].">".$row['category']."</a></li>"; }

Now in the <div> Layout “colunn2” a isset() is sued to check whether $_GET[‘cat’] is set. If it is set the received category name is assigned to the variable $cat.
mysql_query() is used to query names of all the articles corresponding to the received category name from the database table “category_pages”. And the same is displayed with two hyperlinks “edit and “delete” using mysql_fetch_array().
When the “edit” hyperlink is clicked the corresponding “id” of the article is transferred to edit_page.php.

When the “delete” hyperlink is clicked the corresponding “id” of the article is transferred to delete.php

<?php
if(isset($_GET['cat']))
{
$cat=$_GET['cat'];
$qry=mysql_query("SELECT * FROM category_pages WHERE category='$cat' order by category_pages.id DESC", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
echo "<table>";
while($row=mysql_fetch_array($qry))
{
//echo $row['title'];
echo "<tr>";
echo "<td><a href=pages.php?id=".$row['pg_name'].">".$row['hyperlink_name']."</a></td>";
echo "<td><a href=edit_page.php?id=".$row['id'].">edit</a></td>";
echo "<td><a href=delete.php?id=".$row['id'].">delete</a></td>";
echo "</tr>";
}
echo "</table>";
}
?>

A hyperlink “Create primary Pages” is placed which when clicked will transfer the control to primary_page.php.

<a href="primary_page.php" target="_self">Create Primary Pages</a>

A hyperlink “Index Page (Home)” is placed which, when clicked will transfer a value “index” through url variable “home” to administration.php page itself.

<a href=administration.php?home=index>Index Page(Home) </a><br/>

Another hyperlink “Primary pages”, which when clicked will transfer the value “viewall” through url variable “index” to administration.php itself.

<a href=administration.php?index=viewall>Primary Pages </a>

Next in the <div> Layout “column2” a isset() is used to check whether the url variable “id” is set. If it is set mysql_query() is used to query all the data’s from the database table “category_pages”.

Then the queried article names are displayed along with two hyperlinks “edit and “delete”.

When the “edit” is clicked the corresponding article “id” is transferred to edit_page.php. When the “delete” hyperlink is clicked the corresponding article “id” is transferred to delete.php.

if(isset($_GET['id'])=="viewall")
{
$qry=mysql_query("SELECT * FROM category_pages order by category_pages.id DESC ", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
echo "<table>";
/* Fetching data from the field "title" */
while($row=mysql_fetch_array($qry))
{
echo "<tr>";
echo "<td><a href=pages.php?id=".$row['pg_name'].">".$row['hyperlink_name']."</a></td>";
echo "<td><a href=edit_page.php?id=".$row['id'].">edit</a></td>";
echo "<td><a href=delete.php?id=".$row['id'].">delete</a></td>";
echo "</tr>";
}
echo "</table>";
}

Similarly isset() is used to check whether the url variable “index” is set. If it is set, all the data’s with pg_type as menu are queried using mysql_query() and are displayed with “edit” and “delete” hyperlink. When “edit” is clicked the corresponding article “id” is transferred to edit_primary.php. When “delete” is clicked the corresponding article id is transferred to delete.php.

<?php
if(isset($_GET['index'])=="viewall")
{
$qry=mysql_query("SELECT * FROM home_page WHERE pg_type='menu' order by home_page.id DESC ", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
echo "<table>";
/* Fetching data from the field "title" */
while($row=mysql_fetch_array($qry))
{
echo "<tr>";
echo "<td><a href=index.php?page=".$row['pg_name'].">".$row['hyperlink_name']."</a></td>";
echo "<td><a href=edit_primary.php?id=".$row['id'].">edit</a></td>";
echo "<td><a href=delete.php?page=".$row['id'].">delete</a></td>";
echo "</tr>";
}
echo "</table>";
}
?>

Also isset() is used to check whether the url variable “home” is set. If it is set the database table “home_page” with pg_type content is queried using mysql_query() and displayed along with “edit” hyperlink. When “edit” is clicked the correspondiong article “id” is transferred to edit_primary.php

if(!$qry)
{
die("Query Failed: ". mysql_error());
}
echo "<table>";
/* Fetching data from the field "title" */
while($row=mysql_fetch_array($qry))
{
echo "<tr>";
echo "<td><a href=index.php?page=".$row['pg_name'].">".$row['pg_name']."</a></td>";
echo "<td><a href=edit_primary.php?id=".$row['id'].">edit</a></td>";
echo "</tr>";
}
echo "</table>";
}

At the end the database connection is closed using mysql_close.

<?php mysql_close($con); ?>

Output :

Admin Panel for Complete CMS

 

 

 

WEBSITE TUTORIALS