Simple project to understand about register a user account , user login & admin login & admin managing user account:
Step 1:
Create two table first userrecord for user and adminlogin for admin:
Create table userrecord
(id int primary key auto_increment,
namevarchar(200),
contactvarchar(200),
emailvarchar(200),
password varchar(200)
);
Create table adminlogin
(idint primary key auto_increment,
usernamevarchar(200),
passwordvarchar(200)
);
Step 2:
(a)write code for register.html:
<form action="register.php" method="post">
name<input type="text" name="name">
contact<input type="text" name="contact">
email<input type="text" name="email">
password<input type="password" name="password">
<input type="submit" name="submit" value="submit">
(b)write code for register.php :
<?php
$name=$_POST['name'];
$email=$_POST['email'];
$contact=$_POST['contact'];
$password=$_POST['password'];
$con=mysql_connect("localhost","root","");
mysql_select_db("simpleproject",$con);
$sql="select * from userrecord where email='$email'";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if($num>0)
{
echo "<font color=red>email id is already used please use another email id</font>";
}
else
{
$sql1="insert into userrecord(name,email,contact,password) values('$name','$email','$contact','$password')";
mysql_query($sql1);
echo "<font color=red>successfully registered </font>";
}
?>
$email=$_POST['email'];
$contact=$_POST['contact'];
$password=$_POST['password'];
$con=mysql_connect("localhost","root","");
mysql_select_db("simpleproject",$con);
$sql="select * from userrecord where email='$email'";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if($num>0)
{
echo "<font color=red>email id is already used please use another email id</font>";
}
else
{
$sql1="insert into userrecord(name,email,contact,password) values('$name','$email','$contact','$password')";
mysql_query($sql1);
echo "<font color=red>successfully registered </font>";
}
?>
Step 3:
(a)write code for userlogin.html:
<form action="userlogin.php" method="post">
email<input type="text" name="email">
password<input type="password" name="password">
<input type="submit" name="submit" value="submit">
</form>
(b)write code for userlogin.php :
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("simpleproject",$con);
$email=$_POST['email'];
$password=$_POST['password'];
$sql="select email,password from userrecord where email='$email' and password='$password'";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if($num>0)
{
session_start();
$_SESSION['email']=$email;
header('location:userwelcome.php');
}
else
{
echo "invalid userlogin";
}
?>
( c) now write code for userwelcome.php :
<?php
session_start();
if(!isset($_SESSION['email']))
{
header("location:usererror.php");
}
echo "<h1>welcome</h1>";
echo '<a href="userlogout.php">userlogout</a>'.'<br>';
$email=$_SESSION['email'];
echo "welocme =".$email.'<br>';
//display code for user record who made current login//
$con=mysql_connect("Localhost","root","");
mysql_select_db("simpleproject",$con);
$sql="select * from userrecord where email='$email'";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo "<h1>user details </h1>";
echo "ID=".$row['id'];
echo '<br>';
echo "NAME=".$row['name'];
echo '<br>';
echo "CONTACT=".$row['contact'];
echo '<br>';
echo "PASSWORD=".$row['password'];
}
echo '<a href="change_password.php">change password</a>'.'<br>';
echo '<a href="change_profile.php">change profile</a>'.'<br>';
?>
(d)now write code for userlogout.php:
<?php
session_start();
session_destroy();
header('Location:userlogin.html');
?>
(e)write code for usererror.php:
<?php
echo "make login first";
echo '<a href="userlogin.html">login</a>';
?>
(f) Now write code for change_password.php file:
(f) Now write code for change_password.php file:
<?php
session_start();
if(!isset($_SESSION['email']))
{
header("location:usererror.php");
}
?>
<form action="final_change_password.php" method="post">
Enter New Password<input type="password" name="password">
<input type="submit" name="submit" value="change password">
</form>
(g)Now write code for final_change_password.php file:
<?php
session_start();
if(!isset($_SESSION['email']))
{
header("location:usererror.php");
}
?>
<?php
$email=$_SESSION['email'];
$con=mysql_connect("localhost","root","");
mysql_select_db("mandar",$con);
$password=$_POST["password"];
$sql="update userrecord set password='$password' where email='$email'";
$result=mysql_query($sql) or die (mysql_error());
if($result)
{
echo "record update successfully";
}
else
{
echo "record not updated";
}
?>
(h)write code for change_profile.php file:
<?php
session_start();
if(!isset($_SESSION['email']))
{
header("location:usererror.php");
}
?>
<?php
$email=$_SESSION['email'];
$con=mysql_connect("Localhost","root","");
mysql_select_db("simpleproject",$con);
$sql="select * from userrecord where email='$email'";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo '
<form action="final_change_profile.php" method="post">
name<input type="name" name=name value="'.$row['name'].'">
contact<input type="name" name=contact value="'.$row['contact'].'">
<input type="submit" name="submit" value="update-profile">
</form>';
}
(i)write code for final_change_profile.php file:
<?php
session_start();
if(!isset($_SESSION['email']))
{
header("location:usererror.php");
}
?>
<?php
$email=$_SESSION['email'];
$con=mysql_connect("localhost","root","");
mysql_select_db("simpleproject",$con);
$name=$_POST["name"];
$contact=$_POST["contact"];
$sql="update userrecord set name='$name',contact='$contact' where email='$email'";
$result=mysql_query($sql) or die (mysql_error());
if($result)
{
echo "record update successfully";
}
else
{
echo "record not updated";
}
?>
session_start();
if(!isset($_SESSION['email']))
{
header("location:usererror.php");
}
?>
<form action="final_change_password.php" method="post">
Enter New Password<input type="password" name="password">
<input type="submit" name="submit" value="change password">
</form>
(g)Now write code for final_change_password.php file:
<?php
session_start();
if(!isset($_SESSION['email']))
{
header("location:usererror.php");
}
?>
<?php
$email=$_SESSION['email'];
$con=mysql_connect("localhost","root","");
mysql_select_db("mandar",$con);
$password=$_POST["password"];
$sql="update userrecord set password='$password' where email='$email'";
$result=mysql_query($sql) or die (mysql_error());
if($result)
{
echo "record update successfully";
}
else
{
echo "record not updated";
}
?>
(h)write code for change_profile.php file:
<?php
session_start();
if(!isset($_SESSION['email']))
{
header("location:usererror.php");
}
?>
<?php
$email=$_SESSION['email'];
$con=mysql_connect("Localhost","root","");
mysql_select_db("simpleproject",$con);
$sql="select * from userrecord where email='$email'";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo '
<form action="final_change_profile.php" method="post">
name<input type="name" name=name value="'.$row['name'].'">
contact<input type="name" name=contact value="'.$row['contact'].'">
<input type="submit" name="submit" value="update-profile">
</form>';
}
(i)write code for final_change_profile.php file:
<?php
session_start();
if(!isset($_SESSION['email']))
{
header("location:usererror.php");
}
?>
<?php
$email=$_SESSION['email'];
$con=mysql_connect("localhost","root","");
mysql_select_db("simpleproject",$con);
$name=$_POST["name"];
$contact=$_POST["contact"];
$sql="update userrecord set name='$name',contact='$contact' where email='$email'";
$result=mysql_query($sql) or die (mysql_error());
if($result)
{
echo "record update successfully";
}
else
{
echo "record not updated";
}
?>
Now start coding part for admin :
Step 1:
(a)write code for adminlogin.html:
<form action="adminlogin.php" method="post">
username<input type="text" name="username">
password<input type="password" name="password">
<input type="submit" name="submit" value="submit">
(b)now write code for adminlogin.php:
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("abhi",$con);
$username=$_POST['username'];
$password=$_POST['password'];
$sql="select username,password from adminlogin where username='$username' and password='$password'";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
if($num>0)
{
session_start();
$_SESSION['username']=$username;
header('location:display.php');
}
else
{
echo "invalid login";
}
?>
(c )now write code for display.php :
<?php
session_start();
if(!isset($_SESSION['username']))
{
header('location:adminerror.php');
}
?>
<a href="adminlogout.php">Logout</a>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("abhi",$con);
$sql="select * from userrecord";
$result=mysql_query($sql);
echo '<table border=1><tr><td>id</td><td>name</td><td>email</td><td>password</td><td> </td><td> </td></td>';
while($row=mysql_fetch_array($result))
{
echo '<tr>';
echo '<td>';
echo $row['id'];
echo '</td>';
echo '<td>';
echo $row['name'];
echo '</td>';
echo '<td>';
echo $row['email'];
echo '</td>';
echo '<td>';
echo $row["password"];
echo '</td>';
echo '<td><form action="update.php" method="post">
<input type="hidden" name="hidden" value="'.$row['id'].'">
<input type="submit" name="button" value="update">
</form></td>';
echo '<td><form action="delete.php" method="post">
<input type="hidden" name="hidden" value="'.$row['id'].'">
<input type="submit" name="button" value="delete">
</form></td>';
echo '</tr>';
}
echo '</table>';
(d)now write code for update.php file:
<?php
session_start();
if(!isset($_SESSION['username']))
{
header('location:adminerror.php');
}
?>
<?php
$hidden=$_POST["hidden"];
$con=mysql_connect("localhost","root","");
mysql_select_db("abhi",$con);
$sql="select * from userrecord where id='$hidden'";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo '<form action="finalupdate.php" method="post">';
echo 'id<input type="text" name="id" value="'.$row['id'].'">';
echo 'name<input type="text" name="name" value="'.$row['name'].'">';
echo 'contact<input type="text" name="contact" value="'.$row['contact'].'">';
echo '
email<input type="text" name="email" value="'.$row['email'].'">';
echo '
password<input type="password" name="password" value="'.$row['password'].'"> ';
echo '
<input type="hidden" name="hidden" value="'.$row['id'].'">';
echo '
<input type="submit" value="update" name="update">';
echo '</form>';
}
(e)now write code for finalupdate.php :
<?php
session_start();
if(!isset($_SESSION['username']))
{
header('location:adminerror.php');
}
?>
<?php
$hidden=$_POST["hidden"];
$name=$_POST["name"];
$contact=$_POST['contact'];
$email=$_POST["email"];
$password=$_POST["password"];
$con=mysql_connect("localhost","root","");
mysql_select_db("abhi",$con);
$sql="update userrecord set name='$name',contact='$contact',email='$email',password='$password'where id='$hidden'";
mysql_query($sql)or die(mysql_error());
echo "userrecord update successfully";
?>
(f)now write code for delete.php:
<?php
$hidden=$_POST["hidden"];
$con=mysql_connect("localhost","root","");
mysql_select_db("abhi",$con);
$sql="delete from userrecord where id='$hidden'";
mysql_query($sql);
echo "userrecord deleted successfully";
?>
(g)write code for adminerror.php:
<?php
echo "make login first";
echo '<a href="adminlogin.html">login</a>';
?>
(h)now write code for adminlogout.php:
<?php
session_start();
session_destroy();
header('Location:adminlogin.html');
?>
No comments:
Post a Comment