PHP Sample Code For admin_home page
Step 1:
Create a table, login_table with following fields…(username p.k)
Username / Password / type / firstname / lastname / sex / address / phone /Step 2:
Create a new directory admin, create the following files in this directory
Step 3:
Create admin_home.php
Step 4:
Create admin_userslist.php
Step 5:
Create admin_user_delete.php
Step 6:
Create admin_selectuser_to_delete.php
Step 7:
Create header.php (in the root directory)
Step 8:
Create signout.php (in the root directory)
admin_home.php
<?php session_start();
if(isset($_SESSION['type']))
{
if($_SESSION['type']=="Admin")
{
?>
Add Your template page here
<h2> :::[Admin Page]::::</h2>
<?php
echo "Welcome, [". $_SESSION['type']." ". $_SESSION['username']."]br";
?>
<a href="admin_home.php"> :[ Home ]: </a>
<a href="admin_userslist.php"> :[ List Users ]: </a>
<a href="admin_user_delete.php"> :[ Delete User ]: </a>
<a href="../signout.php"> :[ SignOut ]: </a>
</html>
<?php
}
else
{
header("location: ../index.php?error=Invalid User");
}
}
else
{
header("location: ../index.php?error=Invalid User");
}
?>
admin_userslist.php
<?php session_start();
if(isset($_SESSION['type']))
{
if($_SESSION['type']=="Admin")
{
?>
Add Your template page here
<h2> :::[Admin Page]::::</h2>
<?php
echo "Welcome, [". $_SESSION['type']." ". $_SESSION['username']."]<br>";
?>
<a href="admin_home.php"> :[ Home ]: </a>
<a href="admin_userslist.php"> :[ List Users ]: </a>
<a href="admin_user_delete.php"> :[ Delete User ]: </a>
<a href="../signout.php"> :[ SignOut ]: </a>
<table width=80% border=1>
<tr align="center"<td>Sl#<td>Usename<td>Type<td>Firstname<td>Lastname<td>Sex<td>Address<td>Phone
<?php
include '../header.php';
$sql=mysql_query("SELECT * FROM login_table");
$i=1;
while($row=mysql_fetch_array($sql))
{
$dbusername = $row['username'];
$dbtype = $row['type'];
$dbfirstname=$row['firstname'];
$dblastname=$row['lastname'];
$dbsex=$row['sex'];
$dbaddress=$row['address'];
$dbphone=$row['phone'];
if($dbsex=="m"||$dbsex=="M")$dbsex="Male";else $dbsex="Female";
if($i%2==0)
echo "<tr bgcolor=#CC0033<td>".$i."<td>".$dbusername."<td>".$dbtype."<td>".$dbfirstname."<td>".$dblastname." <td>".$dbsex."<td>".$dbaddress."<td>".$dbphone;
else
echo "<tr bgcolor=gray<td>".$i."<td>".$dbusername."<td>".$dbtype."<td>".$dbfirstname."<td>".$dblastname."<td>" .$dbsex."<td>".$dbaddress."<td>".$dbphone;
$i++;
}
}
else
{
header("location: ../index.php?error=Invalid User");
}
}
else
{
header("location: ../index.php?error=Invalid User");
}
?>
admin_user_delete.php
<?php session_start();
if(isset($_SESSION['type']))
{
if($_SESSION['type']=="Admin")
{
?>
Add Your template page here
<h2> :::[Admin Page]::::</h2>
<?php
echo "Welcome, [". $_SESSION['type']." ". $_SESSION['username']."]<br>";
?>
<a href="admin_home.php"> :[ Home ]: </a>
<a href="admin_userslist.php"> :[ List Users ]: </a>
<a href="admin_user_delete.php"> :[ Delete User ]: </a>
<a href="../signout.php"> :[ SignOut ]: </a>
<table width=80% border=1>
<tr align="center"<td>Sl#<td>Usename<td>Type<td>Firstname<td>Lastname<td>Sex<td>Address<td>Phone<TD>Delete
<?php
include '../header.php';
$sql=mysql_query("SELECT * FROM login_table");
$i=1;
while($row=mysql_fetch_array($sql))
{
$dbusername = $row['username'];
$dbtype = $row['type'];
$dbfirstname=$row['firstname'];
$dblastname=$row['lastname'];
$dbsex=$row['sex'];
$dbaddress=$row['address'];
$dbphone=$row['phone'];
if($dbsex=="m"||$dbsex=="M")$dbsex="Male";else $dbsex="Female";
if($i%2==0)
echo "<tr bgcolor=#CC0033<td>".$i."<td>".$dbusername."<td>".$dbtype."<td>".$dbfirstname."<td>".$dblastname." <td>".$dbsex."<td>".$dbaddress."<td>".$dbphone."<td<a href=admin_selectuser_to_delete.php?selected_id=". $dbusername.">DELETE</a>";
else
echo "<tr bgcolor=gray<td>".$i."<td>".$dbusername."<td>".$dbtype."<td>".$dbfirstname."<td>".$dblastname."<td>" .$dbsex."<td>".$dbaddress."<td>".$dbphone."<td<a href=admin_selectuser_to_delete.php?selected_id=". $dbusername.">DELETE</a>";
$i++;
}
}
else
{
header("location: ../index.php?error=Invalid User");
}
}
else
{
header("location: ../index.php?error=Invalid User");
}
?>
admin_selectuser_to_delete.php
<?php session_start();
if(isset($_SESSION['type']))
{
if($_SESSION['type']=="Admin")
{
?>
Add Your template page here
<h2> :::[Admin Page]::::</h2>
<?php
echo "Welcome, [". $_SESSION['type']." ". $_SESSION['username']."]<br>";
?>
<a href="admin_home.php"> :[ Home ]: </a>
<a href="admin_userslist.php"> :[ List Users ]: </a>
<a href="admin_user_delete.php"> :[ Delete User ]: </a>
<a href="../signout.php"> :[ SignOut ]: </a>
<table width=80% border=1>
<tr align="center"<td>Sl#<td>Usename<td>Type<td>Firstname<td>Lastname<td>Sex<td>Address<td>Phone
<?php
include '../header.php';
$selected_id=$_GET['selected_id'];
$sql=mysql_query("delete From login_table where username='".$selected_id."'");
$sql=mysql_query("SELECT * FROM login_table");
$i=1;
while($row=mysql_fetch_array($sql))
{
$dbusername = $row['username'];
$dbtype = $row['type'];
$dbfirstname=$row['firstname'];
$dblastname=$row['lastname'];
$dbsex=$row['sex'];
$dbaddress=$row['address'];
$dbphone=$row['phone'];
if($dbsex=="m"||$dbsex=="M")$dbsex="Male";else $dbsex="Female";
if($i%2==0)
echo "<tr bgcolor=#CC0033<td>".$i."<td>".$dbusername."<td>".$dbtype."<td>".$dbfirstname."<td>".$dblastname." <td>".$dbsex."<td>".$dbaddress."<td>".$dbphone;
else
echo "<tr bgcolor=gray<td>".$i."<td>".$dbusername."<td>".$dbtype."<td>".$dbfirstname."<td>".$dblastname."<td>" .$dbsex."<td>".$dbaddress."<td>".$dbphone;
$i++;
}
echo "<brtr<td>".$selected_id." deleted ...... ";
}
else
{
header("location: ../index.php?error=Invalid User");
}
}
else
{
header("location: ../index.php?error=Invalid User");
}
?>
header.php ( in the root directory)
<?php
$connect = mysql_connect("localhost","root","") or die("Couldn't connect!");
mysql_select_db("phpdb") or die("Couldn't find db");
?>
Signout.php (in the root directory)
<?php
session_start();
session_destroy();
header("location: index.php?error=Logout Successfully!!");
?>