Registration And Login Form In Php And Mysql


In this tutorial, we will discuss how to create a login and signup form using PHP and MySQL database.

For any kind of web application login, signup is the most important thing for security reasons. If we did not have login features in our web application then anyone can access our data and services.

Create a Few pages:

  • database.php: For connecting database
  • signup.php: getting the values from the user
  • login.php: for getting the values from the user
Database.php
<?php
$url='localhost';
$username='root';
$password='';
$db='user';
$conn=mysqli_connect($url,$username,$password,$db);
if(!$conn){
 die('Could not Connect My Sql:' .mysql_error());
}
?>
Signup.php

This step we will create a signup form:

<!DOCTYPE HTML>
<html>
<head>
<title>New user signup From Php Coding Stuff</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
</head>

<body>
<form method="post">
<div class="form-group">
    <label for="exampleInputname">Full Name</label>
    <input type="text" name="name" class="form-control" id="name">
  </div>
  <div class="form-group">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" name="email" class="form-control" id="exampleInputEmail1">
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Password</label>
    <input type="password" name="password" class="form-control" id="exampleInputPassword1">
  </div>
  <input type="submit" class="btn btn-primary" name="submit" value="Submit">
</form>
 
<?php
include("database.php");

  if (isset($_POST['submit'])) {
    $name= $_POST['name'];
$email= $_POST['email'];
$password= $_POST['password'];
    if ($name== '' OR $password =='' OR $email == '') { ?>
                        <script>alert('All Fild Are Required');</script>
                    <?php    }else{
$query="insert into user(name,email,password) values('$name','$email',$password)";
mysqli_query($conn,$query);
?>
<script>alert('Registration Successfully');</script>
<?php
}
 ?>
</body>
</html>
Login.php

Then we will create a Login form:

<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>
<body>

<form method="post">
  <div class="form-group">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" name="email" class="form-control" id="exampleInputEmail1">
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Password</label>
    <input type="password" name="password" class="form-control" id="exampleInputPassword1">
  </div>
  <input type="submit" name="submit" class="btn btn-primary" value="Submit">
</form>

<?php
include("database.php");
if (isset($_POST['submit'])) {
$email= $_POST['email'];
$password= $_POST['password'];
 if ($email== '' OR $password=='') { ?>
                        <script>alert('All Fild Are Required');</script>
                    <?php    }else{
$query="select * from user where email='$email' and password='$password";
$res = mysqli_query($conn,$query);

if(mysqli_num_rows($rs)<1)
	{
		$found="NOT Fount";
	}
	else
	{
		$_SESSION["email"]=$email;
	}
?>
<script>alert('Login Successfully');</script>
<?php

}

?>
</body>
</html>

I hope it can help you...

  1. Hi, I respect you and I like your website as well. It’s an insightful platform. I see here nice details It’s useful to me.

Leave a Reply

Your privacy will not be published. Required fields are marked *

We'll share your Website Only Trusted.!!