Create Signup and Login PHP System

PHP Signup and login is the important part of website. so in this article we will create Singnup and login PHP system with MySQL database.

Signup and Login Form Using PHP & MySQLI (OOPS):

PHP is the king of a website because without PHP website is nothing and PHP normally used for dynamic websites to interact with the database, so in this today article, we will use MySQLI object-oriented concept to create login system you will learn object-oriented MySQLI from scratch.
login php

Follow Steps:

  1. Create Database
  2. Create Database php_crud
    
  3. Table
  4. 
    CREATE TABLE `signup` (
     `id` int(11) NOT NULL AUTO_INCREMENT,
     `name` varchar(50) NOT NULL,
     `email` varchar(100) NOT NULL,
     `password` varchar(255) NOT NULL,
     PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
    
  5. Connect.php
  6. 
    <?php 
    $db = new mysqli("localhost","root","","php_crud");
    if($db->connect_error){
     echo "Connection".$db->connect_error;
    }
     ?>
    
  7. Index.php
  8. 
    <?php include 'connection/connect.php';
    if(isset($_POST['signup'])){
     $name      = $_POST['name'];
     $email     = $_POST['email'];
     $password  = $_POST['password'];
     $confirm   = $_POST['confirm'];
     $reg       = "/^[a-zA-Z ]+$/";
     
     $errors    = array();
     if(empty($name)){
      $errors['name_error'] = "Name is required";
     } else if(!preg_match($reg, $name)){
      $errors['name_error'] = "Only Characters are allowed";
      $name = "";
     }
     if(empty($email)){
      $errors['email_error'] = "Email is required!";
     }else{
      $Email_check = $db->query("SELECT email FROM signup WHERE email = '$email'");
      if($Email_check->num_rows == 0){
    
      }else{
       $errors['email_error'] = "Sorry this email is already exist";
       $email = "";
      }
     }
     if(empty($password)){
      $errors['password_error'] = "Password is required";
     }else if(strlen($password) < 4){
      $errors['password_error'] = "Your password is too short";
      $password = "";
     }
     if(empty($confirm)){
      $errors['confirm_error'] = "Confirm password is required";
     }else if($confirm != $password){
      $errors['confirm_error'] = "Please confirm your password!";
      $confirm = "";
     }
     if(!empty($name) && !empty($email) && !empty($password) && !empty($confirm)){
      $password = password_hash($password,PASSWORD_DEFAULT);
      $Query = $db->query("INSERT INTO signup (name,email,password) VALUES ('$name','$email','$password')");
      if($Query){
       header("location:success.php?signup_success='Your acccount is successfully created!'");
      }else{
       echo "<script>alert('Sorry query not work')</script>";
      }
      
     }
    
    }
    
     ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
     <meta charset="UTF-8">
     <title>Create Signup && Login</title>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
        <style type="text/css">
         ul{
          margin:0;
          padding:0;
         }
         ul li{
          margin:0;
          padding: 0;
          color:red;
          list-style: none;
         }
        </style>
    </head>
    <body>
     <nav class="navbar navbar-expand-lg navbar-light bg-light">
      <div class="container">
      <a class="navbar-brand" href="#">Singup & Login</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
    
      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item active">
            <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
          </li>
          <li class="nav-item">
           <a href="login.php" class="nav-link">login</a>
          </li>
    
          <li class="nav-item">
           
          </li>
        </ul>
        
      </div>
    </div>
    </nav>
    <div class="container" style="margin-top: 50px;">
     <div class="row">
      <div class="col-md-5">
       <div class="card">
        <div class="card-header">
         <h3>Create Account</h3>
        </div><!-- card-header -->
        <div class="card-body">
         <form action="" method="POST">
          <div class="form-group">
           <?php 
                                if(isset($errors)): ?>
                                <?php foreach($errors as $error_show): ?>
                                 <ul>
                                  <li><?php echo $error_show; ?></li>
                                 </ul>
                                <?php endforeach; ?>
                            <?php endif; ?>
    
          </div>
          <div class="form-group">
           <input type="text" name="name" placeholder="Enter Name..." class="form-control" value="<?php if(isset($name)){ echo $name; }?>">
          </div><!-- form-group -->
          <div class="form-group">
           <input type="email" name="email" placeholder="Enter Email..." class="form-control" value="<?php if(isset($email)){ echo $email; }?>">
          </div><!-- form-group -->
          <div class="form-group">
           <input type="password" name="password" placeholder="Create Password..." class="form-control" value="<?php if(isset($password)){ echo $password; }?>">
          </div><!-- form-group -->
          <div class="form-group">
           <input type="password" name="confirm" placeholder="Confirm Password..." class="form-control" value="<?php if(isset($confirm)){ echo $confirm; }?>">
          </div><!-- form-group -->
          <div class="form-group">
           <input type="submit" name="signup" value="Create Account" class="btn btn-success btn-block">
          </div><!-- form-group -->
       </form><!-- form -->
        </div><!-- card-body -->
       </div><!-- card -->
      </div><!-- col -->
     </div><!-- row -->
    </div><!-- container -->
    </body>
    </html>
    
  9. Success.php
  10. 
    <!DOCTYPE html>
    <html lang="en">
    <head>
     <meta charset="UTF-8">
     <title>Document</title>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
    </head>
    <body>
     <?php 
    if(isset($_GET['signup_success'])){
     echo "<div class='alert alert-success text-center'><h1>".$_GET['signup_success']."</h1><a href='login.php'>Login</a></div>";
    }
    
    
     ?>
    </body>
    </html>
    
  11. Login.php
  12. 
    <?php 
    session_start();
    include 'connection/connect.php';
    if(isset($_POST['login'])){
     $email = $_POST['email'];
     $password = $_POST['password'];
     $errors = array();
     $query = $db->query("SELECT * FROM signup WHERE email = '$email'");
     if($query->num_rows == 0){
      $errors['wrong_email'] = "Enter correct email";
     }else{
      $r = $query->fetch_assoc();
      $hash_password = $r['password'];
      if(!password_verify($password, $hash_password)){
             $errors['password_wrong'] = "Your password is wrong";
      }else{
       $_SESSION['user_login'] = $email;
       header("location:home.php");
      }
     }
    }
    
     ?>
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
     <meta charset="UTF-8">
     <title>Document</title>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
    </head>
    <body>
      <div class="container" style="margin-top: 50px;">
       <div class="row">
        <div class="col-md-4">
         <h3>Login User</h3><hr>
         <form action="" method="POST">
          <div class="form-group">
           <?php if(isset($errors)): ?>
            <?php foreach($errors as $error): ?>
             <ul>
              <li>
               <?php echo $error; ?>
              </li>
             </ul>
            <?php endforeach; ?>
           <?php endif; ?>
          </div>
          <div class="form-group">
           <input type="email" name="email" placeholder ="Enter email..." class="form-control" required="">
          </div>
          <div class="form-group">
           <input type="password" name="password" placeholder ="Enter Password..." class="form-control" required="">
          </div>
          <div class="form-group">
           <input type="submit" name="login" value="Login" class="btn btn-success">
          </div>
         </form>
        </div>
       </div>
      </div>
    </body>
    </html>
    
  13. Home.php
  14. 
    <?php 
    session_start();
    if(isset($_SESSION['user_login']))
    {
    echo "<h1>Welcome user</h1><a href='logout.php'>logout</a>";
    }else{
     header("location:login.php");
    }
    
    
     ?>
    
  15. Logout.php
  16. 
    <?php 
    session_start();
    session_destroy();
    header("location:login.php");
    
     ?>
    
Download full source code with SQL database.

[Download full souce code ##download##]

COMMENTS

Name

ajax,1,HTML & CSS,12,PHP,7,
ltr
item
webtipstricks: Create Signup and Login PHP System
Create Signup and Login PHP System
PHP Signup and login is the important part of website. so in this article we will create Singnup and login PHP system with MySQL database.
https://2.bp.blogspot.com/-r_ymzMwb8wM/WtSAl9XUB0I/AAAAAAAABkk/CXx35VtvZvImZNdZ3Aq8feSToKkP1XtkgCLcBGAs/s640/signup%2Band%2Blogin%2Bform.png
https://2.bp.blogspot.com/-r_ymzMwb8wM/WtSAl9XUB0I/AAAAAAAABkk/CXx35VtvZvImZNdZ3Aq8feSToKkP1XtkgCLcBGAs/s72-c/signup%2Band%2Blogin%2Bform.png
webtipstricks
https://www.webtipstricks.com/2017/11/signup-login-php.html
https://www.webtipstricks.com/
https://www.webtipstricks.com/
https://www.webtipstricks.com/2017/11/signup-login-php.html
true
4027471107773963481
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy