Step:- 1 registration.php
<?php
include 'classfile.php';
$edit=new crud();
$row=$edit->editdata();
?>
<!DOCTYPE html>
<html>
<head>
<title>Oops Registration Prectice</title>
</head>
<body>
<form action="insertprocess.php" method="post">
<table border="2" align="center">
<?php
if(isset($_GET['eid']))
{
?>
<input type="text" name="uid" value="<?php echo
$_GET['eid'];
?>">
<?php
}
?>
<tr>
<td>First name</td>
<td><input type="text" name="fname" value="<?php
if(isset($_GET['eid']))
{
echo $row['fname'];
}
?>"></td>
</tr>
<tr>
<td>Last name</td>
<td><input type="text" name="lname" value="<?php
if(isset($_GET['eid']))
{
echo $row['lname'];
}
?>"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" value="<?php
if(isset($_GET['eid']))
{
echo $row['email'];
}
?>"></td>
</tr>
<tr>
<td>Phone Numberr</td>
<td><input type="text" name="phone" value="<?php
if(isset($_GET['eid']))
{
echo $row['phone'];
}
?>"></td>
</tr>
<tr>
<td>Submit</td>
<td colspan="2" align="center">
<input type="submit" value="submit">
</td>
</tr>
</table>
</form>
</body>
</html>
Step:-2 insertprocess.php
<?php
include 'classfile.php';
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$email=$_POST['email'];
$phone=$_POST['phone'];
if(isset($_POST['uid']))
{
$uid=$_POST['uid'];
$update=new crud();
$update->update($fname,$lname,$email,$phone,$uid);
}
else
{
$insert= new crud();
$insert->insertdata($fname,$lname,$email,$phone);
}
?>
Step:- 3 classfile.php
<?php
session_start();
class crud
{
public function logindata($email,$password)
{
$conn=mysqli_connect("localhost","root","","oopsprectice")or die("Error in Connection");
$query="select * from loginnew where email='$email'and password='$password'";
$res=mysqli_query($conn,$query);
$row=mysqli_fetch_array($res);
$count=mysqli_num_rows($res);
if($count==1)
{
$_SESSION['user_id']=$row['id'];
header("location:dashboard.php");
echo "sucess";
}
else
{
echo "Plz enter valid email and password";
}
}
public function insertdata($fname,$lname,$email,$phone)
{
$conn=mysqli_connect("localhost","root","","oopsprectice")or die("Error in connection");
$query="insert into oopsprec values('','$fname','$lname','$email','$phone')";
if(mysqli_query($conn,$query))
{
echo "Record is Inserted..";
}
else
{
echo "Record is Not Inserted..";
}
}
public function loginnew($email,$password)
{
$conn=mysqli_connect("localhost","root","","oopsprectice")or die("Error in connection");
$query="insert into loginnew values('','$email','$password')";
if(mysqli_query($conn,$query))
{
echo "Record is Inserted..";
}
else
{
echo "Record is Not Inserted..";
}
}
public function viewdata()
{
$conn=mysqli_connect("localhost","root","","oopsprectice")or die("connection Error");
$query="select * from oopsprec";
$res=mysqli_query($conn,$query);
return $res;
}
public function editdata()
{
$conn=mysqli_connect("localhost","root","","oopsprectice")or die("Connection Error");
if(isset($_GET['eid']))
{
$edit_id=$_GET['eid'];
$query="select * from oopsprec where id='$edit_id'";
$res=mysqli_query($conn,$query);
$row=mysqli_fetch_array($res);
return $row;
}
}
public function update($fname,$lname,$email,$phone,$uid)
{
$update_id=$_POST['uid'];
$conn=mysqli_connect("localhost","root","","oopsprectice")or die("Connnection Error");
$query="update oopsprec set fname='$fname',lname='$lname',email='$email',phone='$phone' where id='$update_id'";
if(mysqli_query($conn,$query))
{
echo "Record is Updated..";
}
else
{
echo "Record is Not Updated..";
}
}
public function deletedata()
{
if(isset($_GET['did']))
{
$delete_id=$_GET['did'];
$conn=mysqli_connect("localhost","root","","oopsprectice")or die("connection Error");
$query="delete from oopsprec where id='$delete_id'";
if(mysqli_query($conn,$query))
{
echo "Record is Deleted..";
}
else
{
echo "Record is Not Deleted..";
}
}
}
}
?>
Step:-4 viewdata.php
<?php
include 'classfile.php';
$view= new crud();
$res=$view->viewdata();
$delete= new crud();
$delete->deletedata();
?>
<!DOCTYPE html>
<html>
<head>
<title>View Data</title>
</head>
<body>
<form action="" method="post">
<table border="2" align="center">
<tr>
<th>Id</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Phone Number</th>
<th>Action</th>
</tr>
<?php
while($row=mysqli_fetch_array($res))
{
?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['fname'];?></td>
<td><?php echo $row['lname'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['phone'];?></td>
<td>
<a href="registration.php?eid=<?php echo $row['id'];?>">Edit /</a>
<a href="viewdata.php?did=<?php echo $row['id'];?>">Delete</a>
</td>
</tr>
<?php
}
?>
</table>
</form>
</body>
</html>
Step:-5 loginnew.php
<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
</head>
<body>
<form action="loginnewprocess.php" method="post">
<table border="2" align="center">
<tr>
<td>Email</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="password"></td>
</tr>
<tr>
<td>Submit</td>
<td colspan="2" align="center"><input type="submit" value="submit"></td>
</tr>
</table>
</form>
</body>
</html>
Step:-6 loginnewprocess.php
<?php
include 'classfile.php';
$email=$_POST['email'];
$password=$_POST['password'];
$login= new crud();
$login->loginnew($email,$password);
?>
Step:-7 login.php
<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
</head>
<body>
<form action="loginprocess.php" method="post">
<table border="2" align="center">
<tr>
<td>Email</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="password"></td>
</tr>
<tr>
<td>Submit</td>
<td colspan="2" align="center"><input type="submit" value="submit"></td>
</tr>
</table>
</form>
</body>
</html>
Step:-8 loginprocess.php
<?php
include 'classfile.php';
$email=$_POST['email'];
$password=$_POST['password'];
$login= new crud();
$login->logindata($email,$password);
?>
Step:-9 dashbaord.php
<?php
$conn=mysqli_connect("localhost","root","","oopsprectice")or die("Connection Error");
session_start();
if(isset($_SESSION['user_id']))
{
$id=$_SESSION['user_id'];
}
else
{
header("location:login.php");
}
?>
<a href="logout.php">Logout</a>
Step:-10 logout.php
<?php
session_start();
session_destroy();
header("location:login.php");
?>