ASSIGNMENT-11PHP
ASSIGNMENT-11PHP
Ans:-
DBConnect.php
<?php
$server='localhost';
$uname='root';
$pass='';
$db='bcadb';
$con=mysqli_connect($server,$uname,$pass,$db);
if ($con) {
echo "DB($db) Connection done Successfully."; }
else {
echo "Sorry!! DB($db) is not Connected!";} ?>
reg.php
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-
Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<title>Registration pages</title>
</head>
<body>
<h1>Registration Page</h1>
<form action="reg.php" method="post">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input name="email" type="email" class="form-control" id="exampleInputEmail1"
aria-describedby="emailHelp" placeholder="Enter email">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Name</label>
<input name="clName" type="text" class="form-control" id="exampleInputEmail1"
aria-describedby="emailHelp" placeholder="Enter Your Name">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Father's Name</label>
<input name="fname" type="text" class="form-control" id="exampleInputEmail1"
aria-describedby="emailHelp" placeholder="Enter your father's name">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Mobile No</label>
<input name="mobile" type="tel" class="form-control" id="exampleInputEmail1"
aria-describedby="emailHelp" placeholder="Enter Mobile Number">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Set Password</label>
<input name="pass" type="password" class="form-control"
id="exampleInputPassword1" placeholder="Password">
</div>
<input type="submit" class="btn btn-primary" value="Submit">
</form>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-
KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-
ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-
JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
</body>
</html>
<?php
require "DBConnect.php";
if($_SERVER['REQUEST_METHOD']=='POST'){
if(isset($_POST['email'])&&
isset($_POST['clName'])&&
isset($_POST['fname']) &&
isset($_POST['mobile'])&&
isset($_POST['pass']))
{
$e1=$_POST['email'];
$n1=$_POST['clName'];
$fn1=$_POST['fname'];
$m1=$_POST['mobile'];
$p1=$_POST['pass'];
// Set Encrypted Password
// $enPs1=password_hash($p1,PASSWORD_DEFAULT);
$qur1="INSERT INTO logindetail VALUES ('$e1','$n1','$fn1','$m1','$p1')";
$exe1=mysqli_query($con,$qur1);
if($exe1){
echo '
<script>
alert("Registration Successful");
window.location.href="login3.php";
</script> ';}
else{
echo '
<script>
alert("Sorry!! Registration cannot Done!");
</script>
'; }}}
?>
login3.php
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-
Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<title>Login</title>
</head>
<body>
<h1>Login Page</h1>
<form action="login3.php" method="post">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input name="email" type="email" class="form-control" id="exampleInputEmail1"
aria-describedby="emailHelp" placeholder="Enter email">
<small id="emailHelp" class="form-text text-muted">We'll never share your email
with anyone else.</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input name="pass" type="password" class="form-control"
id="exampleInputPassword1" placeholder="Password">
</div>
<input type="submit" class="btn btn-primary" value="LogIn">
</form>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-
KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-
ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-
JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
</body>
</html>
<?php
require "DBConnect.php";
if($_SERVER['REQUEST_METHOD']=='POST'){
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['pass']);
$query = "SELECT * FROM logindetail WHERE email='$email' LIMIT 1";
$result = mysqli_query($con, $query);
if($result){
if(mysqli_num_rows($result) == 1){
$row = mysqli_fetch_assoc($result);
$hashedPassword = $row['pass'];
if (password_verify($password, $hashedPassword))
{
if($_SERVER['REQUEST_METHOD']=='POST'){
$ce1=$_POST['email'];
$cp1=$_POST['pass'];
$qur1="SELECT * FROM logindetail WHERE email='$ce1';";
$exc1=mysqli_query($con,$qur1);
$rowCount=mysqli_num_rows($exc1);
// Successful Login Code Starts here
if($rowCount==1){
session_start();
$rowFetch=mysqli_fetch_assoc($exc1);
$_SESSION['name']=$rowFetch['clName'];
$_SESSION['fname']=$rowFetch["fname"];
$_SESSION['monum']=$rowFetch['mobile'];
echo '
<script>
alert("Login Successful.");
window.location.href="dashboard.php";
</script>
'; }
else{
echo '
<script>
alert("Sorry!! Login Unsuccessful!");
</script>
';} }}
else
{
echo 'Invalid password';}
}else{
echo 'Invalid Email Address';}
}else{
Dashboard.php
<?php
session_start();
echo "Welcome User ".$_SESSION['name'];
echo "<br> Father's Name ".$_SESSION['fname'];
echo "<br> Mobile No is ".$_SESSION['monum'];
?>