Simple register page in PHP

This is a simple register page in PHP which can take name, email and password of the user and submit the entered data to MySQL database. We have given frontend and backend code to create simple register page in PHP.

Simple register page in PHP



Follow these steps to create register page in PHP

Step - 1: Create a new page register.php and paste the code

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Create New Account</title>
<link rel="stylesheet" href="">
<style>
*{
padding:0;
margin:0;
}
.form-container{
background:#EDEFEF;
max-width:650px;
box-shadow:0 0 2px #A6A7A8;
margin:auto;
}
.form-heading{
background:#096CAB;
color:#EEF4FA;
padding:15px;
}
.form-body{
padding:25px;
}
label{
display:block;
color:#424344;
margin-bottom:2px;
font-weight:normal;
font-size:14px;
}
.form-group{
width:90%;
margin:auto;
margin-bottom:20px;
}
.form-control{
width:100%;
border:none;
background:transparent;
border-bottom:2px solid #C3C4C4;
box-sizing: border-box;
}
.form-group input[type=text]:focus{
outline:none;
border-bottom:2px solid #70A7E0;
color:#565757;
padding-top:15px;
}
.btn-primary{
padding:10px 20px 10px 20px;
background:#096CAB;
color:#ffffff;
border:none;
box-shadow:0 0 2px #2267C6;
cursor:pointer;
}
.form-link{
color:#626363;
font-size:13px;
margin-top:15px;
}
.form-link a{
color:#076EB0;
text-decoration: none;
}
.error{
color:#F50505;
font-size:12px;
}
.success{
background:#7CC02C;
color:#DCFAA1;
font-size:13px;
padding:12px;
text-align:center;
margin-bottom:20px;
}
</style>
</head>
<body>
<div class="form-container">
<div class="form-heading">
Create New Account
</div>
<div class="form-body">
<form action="formSubmit.php" method="post" accept-                                           charset="utf-8">
<div class="form-group">
    <label for="Name">Name</label>
    <input class="form-control" type="text" name="name"                                             autocomplete="off" required>
</div>
<div class="form-group">
    <label for="Email">Email</label>
    <input class="form-control" type="text" name="email"                                             required>
</div>
        <div class="form-group">
    <label for="Name">Password</label>
    <input class="form-control" type="text" name="password"                                         required>
</div>
<div class="form-group">
    <label for="Confirm Password">Confirm Password</label>
    <input class="form-control" type="text" name="conpassword"                                 required>
</div>
<div class="form-group">
    <input class="btn-primary" type="submit" name="submit"                                         value="Signup">
<div class="form-link">
    Already have an account? <a href="#">Login Here</a>
        </div>
    </div>
        </form>
    </div>
</div>
    </body>
</html>

Step - 2: Open phpmyadmin and create a new table user
                 create three columns name, email, password

Step - 3: Create a new page formSubmit.php and paste the code

<?php 
$con = mysqli_connect('localhost','root','','practice_db'); //replace practice_db with your database name
if(isset($_POST['submit']))
{
$name = mysqli_real_escape_string($con,$_POST['name']);
$email = mysqli_real_escape_string($con,$_POST['email']);
$password = mysqli_real_escape_string($con,$_POST['password']);
$conpass = mysqli_real_escape_string($con,$_POST['conpassword']);
if(!empty($name) && !empty($email) && !empty($password) && !empty($conpass))
{
if($password == $conpass)
{
$query = "insert into users(name,email,password) values('$name','$email','$password')";
$result = mysqli_query($con,$query) or die(mysqli_error($con));
if($result)
{
echo "<script>alert('Successfully registered');</script>";
echo "<script>location.href='dashboard.php'</script>";
}
}
else
{
echo "<script>alert('Both passwords are not match');</script>";
echo "<script>location.href='register.php'</script>";
}
}
else
{
echo "<script>alert('Please fill all input fields');</script>";
echo "<script>location.href='register.php'</script>";
}
}

 ?>

It's done now and hope you have successfully created you register page and if any query or suggestion please leave a comment.
If this tutorial is helpful then please share this to your friends and like our facebook page.

Post a Comment

0 Comments