Professional Documents
Culture Documents
Tutorial
So when a user enters correct username and password in login.php page, that is
verified by verify_user.php, which in turn transfers to admin_panel.php page.
admin_panel.php
<?php
session_start();
if(isset($_SESSION['name']))
{
if(!$_SESSION['name']=='admin')
{
header("Location:login.php?id=You are not authorised to access this page unless you
are administrator of this website");
}
}
else
{
header("Location:login.php?id=You are not authorised to access this page unless you
are administrator of this website");
}
?>
<?php
/*
connecting to mysql database
hostname : localhost
username : root
password : 123456
*/
$con = mysql_connect("localhost","root","123456");
if(!$con)
{
die("connection to database failed".mysql_error());
}
session_start();
And the following if condition is to verify whether the logged in user is a authorized
administrator. If the session is not verified as admin, the url will be directed to
login.php page with a message passed through the url variable id. The following code
does that.
if(isset($_SESSION['name']))
{
if(!$_SESSION['name']=='admin')
{
header("Location:login.php?id=You are not authorised to access this page unless
you are administrator of this website");
}
}
else
{
header("Location:login.php?id=You are not authorised to access this page unless
you are administrator of this website");
}
Then as usual php connects to mysql database using hostname, username and
password with mysql_connect().
$con = mysql_connect("localhost","root","123456");
if(!$con)
{
die("connection to database failed".mysql_error());
}
$dataselect = mysql_select_db("cms",$con);
A hyperlink to create a New Category is placed, which when clicked will transfer to
new new_category.php page.
Also an option to create a new article is placed, which when clicked will transfer to
create_new.php page.
View all articles options is placed which when clicked will pass a value “viewall”
through the url variable id to the admin_panel.php page itself.
Then the CMS database table category is queried to display the names of all the
available categories. And the category names are displayed as hyperlinks, which when
clicked will pass the respective category name to the url variable “cat” in the
admin_panel.php page itself.
Next a conditional statement is used to check whether the url variable id holds the
value “viewall”.
if(isset($_GET['id'])=="viewall")
If the value is set the CMS database table articles is queried to display the names of all
the available articles.
And these article title’s are displayed as hyperlinks in the 1st column of each table
row.
The 2nd column of each table row is filled with edit option, which when clicked will
pass their corresponding article id to the edit_article.php page.
The third column of the table rows are filled with delete option, which when clicked
will pass the corresponding article id to delete_article.php page.
A conditional statement is used to check whether the url variable is set. If it is set the
CMS database table articles is queried with the particular category name received
through the url variable “cat” to display all the articles belonging to that particular
category.
if(isset($_GET['cat']))
{
$cat=$_GET['cat'];
$qry=mysql_query("SELECT * FROM articles WHERE category='$cat' order
by articles.id DESC", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
echo "<table>";
And those articles are displayed in the 1st columns of the table, whereas the 2nd and
3rd columns are used for editing the articles and deleting the articles respectively.
while($row=mysql_fetch_array($qry))
{
echo "<tr>";
echo "<td><a href=articles.php?id=".$row['id'].">".$row['title']."</a></td>";
echo "<td><a href=edit_article.php?id=".$row['id'].">edit</a></td>";
echo "<td><a href=delete_article.php?id=".$row['id'].">delete</a></td>";
echo "</tr>";
}
Output :
admin_style.css
#hold {
float: left;
height: 500px;
width: 900px;
position: relative;
}
#top {
float: left;
height: 60px;
width: 900px;
position: relative;
background-color: #F60;
}
#log {
height: 25px;
width: 900px;
float: left;
position: relative;
}
#left {
float: left;
width: 300px;
position: relative;
padding-top: 10px;
padding-left: 20px;
}
#right {
float: left;
width: 500px;
padding-top: 10px;
padding-left: 20px;
position: relative;
left: 20px;
}
#hold #top h2 {
color: #EE4902;
}
#hold #top h2 {
color: #000;
}
#hold #top h2 {
color: #FFF;
}
#work_area {
float: left;
width: 800px;
position: relative;
padding-top: 20px;
padding-left: 50px;
}
#hold #work_area h2 {
color: #EE4902;
}
#hold #work_area #form1 p {
color: #EE4902;
}
#hold #work_area p {
color: #EE4902;
}
#hold #work_area #form1 {
color: #EE4902;
}
table
{
border:1px solid black;
border-collapse:collapse;
}
td
{
border:1px solid black;
}