registration-form-in-php-mysqli-php-guru

In this tutorial, we learn how to create a registration form in PHP MySQL with validation. if you searching for a form with validation then this tutorial is best for you.

1 . Registration form Design

form.php

create a new folder in the htdocs folder give a folder as you want. then create a file in that folder and save it as form.php then copy the code given below if you want to use another design of you can you use your design but make changes in input fields as I am doing in my form design for validation.

<!DOCTYPE html>
<html>
<head>
    <title>Registration From in PHP by Yourphpguru</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
      <style type="text/css">
          .bg-primary {
            background-color: #1a52c6;
        }
        .lab {
            color: red;
        }   
      </style>
</head>
<body class="bg-primary">
    <h2 style="margin-left: 420px;margin-top: 100px;">Registration From in PHP with Validation</h2>
    <div class="row" style="margin-top: 60px;margin-left: 100px;">
        <div class="col-md-2"></div>
        <div class="col-md-6">
            <div class = "well">
            <form class="form-horizontal" method="post" action="insert.php">
              <div class="form-group">
                <label class="control-label lab col-sm-3" for="fullname">Full Name:</label>
                <div class="col-sm-6">
                  <input type="text" class="form-control" id="fullname" name="fullname" placeholder="Enter Full Name"
                  oninvalid="this.setCustomValidity('Please Enter Full Name')" oninput="setCustomValidity('')" required>
                </div>
              </div>
              <div class="form-group">
                <label class="control-label lab col-sm-3" for="email">Email:</label>
                <div class="col-sm-6">
                  <input type="email" class="form-control" id="email" name="email" placeholder="Enter Email" oninvalid="this.setCustomValidity('Please Enter valid email')" oninput="setCustomValidity('')"required>
                </div>
              </div>
              <div class="form-group">
                <label class="control-label lab col-sm-3" for="phone">Phone Number:</label>
                <div class="col-sm-6">
                  <input type="text"  maxlength="10" class="form-control" id="phone" name="phone" placeholder="Enter Phone Number" oninvalid="this.setCustomValidity('Please Enter Phone Number')" oninput="setCustomValidity('')" required>
                </div>
              </div>
              <div class="form-group">
                <label class="control-label lab col-sm-3" for="dob">Date Of Birth:</label>
                <div class="col-sm-3">
                  <input type="date" name="dob" style="color: black;">
                </div>
              </div>
           
              <div class="form-group">
                <label class="control-label lab col-sm-3" for="gender">Gender:</label>
                <div class="col-sm-3">
                    <select class="form-control" name="gender" required>
                        <option value="">select</option>
                        <option value="male">Male</option>
                        <option value="female">Female</option>   
                    </select>   
                </div>
              </div>
           
              <div class="form-group">
                <div class="col-sm-offset-3 col-sm-10">
                  <button type="submit" class="btn btn-default">Submit</button>
                </div>
              </div>
            </form>
            </div>
        </div>
        <div class="col-md-2"></div>
    </div>
</body>
</html>

2. Creating a Table for registration form

Now create a new database give name as registration and create a new table in the database with rid, full name, email, phone, dob, gender, date. or copy code and paste in SQL and click on go.

CREATE TABLE register(rid INT(250) UNSIGNED AUTO_INCREMENT PRIMARY KEY,fullname VARCHAR(200), email VARCHAR(200),phone VARCHAR(200),dob VARCHAR(200), gender VARCHAR(200) ,date datetime);   

3. Connection with mysqli database

Now create a new file and save as db.php and copy the code and paste in db.php file.

db.php

<?php 
$servername="localhost";
$username="root";
$password="";
$dbname="registration";
$server_time=date("Y-m-d H:i:s");
$conn=new mysqli("$servername","$username","$password","$dbname");
if($conn){
    //echo "Connected Successfully";
}else{
    echo "Failed to Connect";
} 
?>

4. Insert Query For Registration form

Now create another file and save it as insert.php. On this page, we write the insert query to insert our information to store in the register table.
insert.php

<?php
include"db.php";
$fullname=$_POST['fullname'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$dob=$_POST['dob'];
$gender=$_POST['gender'];
$query=mysqli_query($conn,"insert into register(fullname,email,phone,dob,gender,date)values('$fullname','$email','$phone','$dob','$gender','$server_time')");
if($query){
  echo "<script>setTimeout(\"location.href = 'form.php';\",00);</script>";   
}
?>

Now you can Fill all the information your registration page is ready to use

For more understanding watch below video :-

If Anyone Need Help or Some Error Occur Join this Group By Clicking on Link.
I Will Help You.

Whatsapp Group:- chat.whatsapp.com

THANK YOU
PHP-GURU

Leave a Reply

Your email address will not be published. Required fields are marked *