How we can create a Simple Registration form in php

Create a simple Registration form in PHP


Registration form in PHP: Hi readers today we are going to create a Simple Registration form using Php script and  MySQL.This Registration and Login management system is an important concept in any website or web application which is common too. Here we are providing the tutorial on the simple Registration form in PHP which guides you step-by-step and Login management system will be explained in our next tutorial.Here we start a session on Registration form in PHP

Step1 : Create a Database and table  directly from the PHPMyAdmin 

open localhost/phpmyadmin and open sql tab and run the below sql query command

Create Database session;

create table register(
id int(5) NOT NULL  AUTO_INCREMENT PRIMARY KEY,
name varchar(30),
username varchar(30) NOT NULL,
password varchar(10) NOT NULL,
email varchar(30) NOT NULL,
status int(11),
last_login DATETIME NOT NULL
);

Step 2: Create a simple Registration form in PHP

create a file with name registration.php and copy below PHP code in a file and save it.

<!Doctype html>
<html>
<head><title>Simple Registration form in PHP</title>
<style>
.margin
{
margin-top:15px;
}
</style>
</head>
<body>
 <!--Registration form -->
<form action="register.php" method="post">
<div class="margin">
Enter Name:
<input type="text" name="name" />
</div>
<div class="margin">
Enter Username:
<input type="text" name="username"/>
</div>
<div class="margin">
Enter Password:
<input type="password" name="password"/>
</div>
<div class="margin">
Enter E-mail Id:
<input type="email" name="email"/>
</div>
<div class="margin">
<input type="submit" name="Register" value="submit"/>
</div>
</form>
 <!--end of form-->
</body>
</html>


Step 3: Creating a ‘Register.php’ for inserting records:

Register.php

<!Doctype html>
<html>
<head><title>creating table register</title>
<head>
<body>
<!--php code begins-->
<?php

//Determine if the value is set and Not null using isset() i.e user has submitted the form or not
if(isset($_POST['Register'])){

//get values of the Registration form submited by user

$name=$_POST['name'];
$username=$_POST['username'];
$user_password=$_POST['password'];
$email=$_POST['email'];

//create a connection with database session using mysqli_connect()
$conn = mysqli_connect("localhost","root","","session");
//check the connection
if (mysqli_connect_errno())
{
echo 'MySQLi Connection was not established: ' . mysqli_connect_error();
}

//insert records in register table in session database
$sql="insert into register(name,username,password,email,status,last_login) 
 VALUES('".$name."','".$username."','".$user_password."','".$email."','0',now())";

//run the above query using mysqli_query()
$result=mysqli_query($conn,$sql);

if($result)
{ 
 echo 'Record has been inserted succesfully';
}
else
{ 
echo 'Record has not been inserted succesfully'; 
}

//close the connection
mysqli_close($conn);
}

else
{
echo 'Please Submit the form first.'; 
}

?>
<!--php code ends-->
</body>
</html>

 


Snapshot View:

Enter the fields of Registration Form:

registration form in php
registration form in php

After Submitting Form:


I hope you would like this tutorial of creating Registration Form in PHP script and MySQL!

Leave a Comment