HOW TO CREATE A REGISTRATION FORM IN PHP WITH MYSQL DATABASE?
success.php
Hope this tutorial was helpful.
Hello
readers in this article we will learn how to create a registration form in php
with mysql database.
There are two view pages i.e., signup.php and success.php,
signup.php will be used to take input from the users and validate the user
inputs i.e username password and confirm password.
If everything goes right
then user registration will be successful l and user will be redirected to
success.php, see below eample.
signup.php
<?php
session_start();
$msg="";
$msg1="";
$cmsg="";
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$username=$_POST['id'];
$pwd=$_POST['pwd'];
$cpwd=$_POST['cpwd'];
$connect=mysqli_connect("localhost","root","","login");
$query=mysqli_query($connect1,"INSERT INTO signup
VALUES('$username','$pwd')");
$_SESSION['username'] =
$username;
echo "
<script>alert('Success! Redirecting To Success Page');
window.location='success.php';
</script>";
}
?>
<script>
function
Validate(){
var
id=document.getElementById('id');
var
pwd=document.getElementById('pwd');
var
cpwd=document.getElementById('cpwd');
var
sc=document.getElementById('sc');
var
iderror=document.getElementById('iderror');
var
pwderror=document.getElementById('pwderror');
var
cpwderror=document.getElementById('cpwderror');
//reset error msg
iderror.innerHTML="";
pwderror.innerHTML="";
cpwderror.innerHTML="";
if(id.value.length<6 || id.value.length > 20){
iderror.innerHTML="Username
Must be 6 To 20 Character Long";
iderror.style.color="red";
}
else if(pwd.value.length<6
|| pwd.value.length >15){
pwderror.innerHTML="Password
Must Be 10 To 15 Character Long";
pwderror.style.color="red";
}
else if(cpwd.value!=pwd.value){
cpwderror.innerHTML="Password
Mismatch";
cpwderror.style.color="red";
}
else{
document.myForm.submit();
}
}
</script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible"
content="IE=edge">
<meta name="viewport" content="width=device-width,
initial-scale=1">
<!-- The above 3 meta tags *must* come first in the
head; any other head content must come *after* these tags -->
<title>User_Registration</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body >
<div class="container" style="margin-top:-32px">
<div class="col-lg-4"></div>
<div class="col-lg-4">
<div class="jumbotron" style="margin-top:80px; background:linear-gradient(skyblue
80%,orangered 20%);"><br>
<h3><font color=orangered>Signup Please</font></h3>
<form method="post" action=""
name="myForm">
<div class="form-group">
<label><font color=white>Username:</font></label>
<input type="text" class="form-control"
id="id" name="id" placeholder="UserName..."
>
<font color="red"><?php echo $msg1; ?></font>
<div id="iderror"></div>
</div>
<div class="form-group">
<label><font color=white>PASSWORD:</font></label>
<input type="password" class="form-control"
id="pwd" name="pwd"
placeholder="Password 6 to 10 char only ">
<div id="pwderror"></div>
</div>
<div class="form-group">
<label><font color=white>CONFIRM PASSWORD:</font></label>
<input type="password" placeholder="Confirm
password..." class="form-control"
id="cpwd" name="cpwd">
<fonr color="red"><?php echo
$cmsg;?></font>
<div id="cpwderror"></div>
</div>
<button type="button" class="btn
btn-primary" onclick="Validate()" >SignUp </button>
<button type="button" class="btn
btn-danger" onclick="login_page()">Login? </button></form>
</div>
</div>
</div>
<script>
function
login_page(){
window.location='login.php';
document.write("<font
color=blue>"+'please wait while redirecting to login page...'+"</font>");
setTimeout('login_page()',3000);
}
</script>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins)
-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or
include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
success.php
<?php
session_start();
if(!isset($_SESSION['username']))
{
echo "Please Login First
To Access This Page";
}
?>
<html>
<head>
<title>
SignUp Success
</title>
</head>
<body>
<h3>Welcome</h3>
<b><?php echo $_SESSION['username'];?></b>
</body>
</html>
Hope this tutorial was helpful.
No comments