how to create login form in php
how to create login form in php with MySQL
Login Form
EXAMPLE :-
<?php
include 'connection.php';
if(isset($_POST['b1']))
{
$email = $_POST['uem'];
$pass = $_POST['upwd'];
$q="SELECT * FROM userdetails WHERE uem =
'$email' AND upwd ='$pass'";
$rs = mysqli_query($cn,$q);
$count = mysqli_num_rows($rs);
if($count ==1)
{
session_start();//start
$data = mysqli_fetch_assoc($rs);
$_SESSION['id'] = $data['uid'];//create
echo "<script>
alert('login Successfully');
window.location.href='profile.php';
</script>";
}
else
{
echo "<script>
alert('Invalid Credetials');
</script>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<title>User Login</title>
<link rel="stylesheet"
href="css/bootstrap.css">
</head>
<body class="">
<div class="col-md-4 bg-white shadow-lg
mx-auto mt-5
p-3">
<h1 class="text-center text-primary">
Login Here
</h1>
<form action="login.php" method="post">
<label>Email Address</label>
<input type="email" name="uem" class="
form-control mb-1"
required>
<label>Password</label>
<input type="password" name="upwd"
class="form-control mb-1"
required>
<div class="text-center">
<input type="submit" value="Login"
name="b1" class="btn btn-primary">
<a href="index.php" class="btn btn-danger">
Create An account ?</a>
<br>
<p class="text-center my-3">
<a href="forgot-password.php">
forgot password ?
</a>
</p>
</div>
</form>
</div>
</body>
</html>
Post a Comment