html code
<!DOCTYPE html>
<html>
<head>
<title>MM</title>
<style>
body
{
margin:0px;
background-color: #293f50;
color:#f9fcf5;
font-family:Arial, Helvetica, sans-serif;
}
#main{width:600px; height:auto; overflow:hidden; padding-bottom:20px; margin-left:auto; margin-right:auto;
border-radius:5px; padding-left:10px; margin-top:100px; border-top:3px double #f1f1f1;
border-bottom:3px double #f1f1f1; padding-top:20px;
}
#main table{font-family:"Comic Sans MS", cursive;}
/* css code for textbox */
#main .tb{height:28px; width:230px; border:1px solid #f26724; color:#fd7838; font-weight:bold; border-left:5px solid #f7f7f7; opacity:0.9;}
#main .tb:focus{height:28px; border:1px solid #f26724; outline:none; border-left:5px solid #f7f7f7;}
/* css code for button*/
#main .btn{width:150px; height:32px; outline:none; color:#f7f7f7; font-weight:bold; border:0px solid #f26724;
text-shadow: 0px 0.5px 0.5px #fff; border-radius: 2px; font-weight: 600; color: #f26724; letter-spacing: 1px;
font-size:14px; background-color:#f1f1f1; -webkit-transition: 1s; -moz-transition: 1s; transition: 1s;}
#main .btn:hover{background-color:#f26724; outline:none; border-radius: 2px; color:#f1f1f1; border:1px solid #f1f1f1;
-webkit-transition: 1s; -moz-transition: 1s; transition: 1s; }
</style>
<script>
function registration()
{
var name= document.getElementById("t1").value;
var email= document.getElementById("t2").value;
var uname= document.getElementById("t3").value;
var pwd= document.getElementById("t4").value;
var cpwd= document.getElementById("t5").value;
//email id expression code
var pwd_expression = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-])/;
var letters = /^[A-Za-z]+$/;
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(name=='')
{
alert('Please enter your name');
}
else if(!letters.test(name))
{
alert('Name field required only alphabet characters');
}
else if(email=='')
{
alert('Please enter your user email id');
}
else if (!filter.test(email))
{
alert('Invalid email');
}
else if(uname=='')
{
alert('Please enter the user name.');
}
else if(!letters.test(uname))
{
alert('User name field required only alphabet characters');
}
else if(pwd=='')
{
alert('Please enter Password');
}
else if(cpwd=='')
{
alert('Enter Confirm Password');
}
else if(!pwd_expression.test(pwd))
{
alert ('Upper case, Lower case, Special character and Numeric letter are required in Password filed');
}
else if(pwd != cpwd)
{
alert ('Password not Matched');
}
else if(document.getElementById("t5").value.length < 6)
{
alert ('Password minimum length is 6');
}
else if(document.getElementById("t5").value.length > 12)
{
alert ('Password max length is 12');
}
else
{
alert('Thank You for Registering with us');
}
}
</script>
</head>
<body>
<!-- Main div code -->
<div id="main">
<div class="h-tag">
<h2>Create Your Account</h2>
</div>
<!-- create account div -->
<div class="login">
<form action="signup.php" method="post">
<table cellspacing="2" align="center" cellpadding="8" border="0">
<tr>
<td align="right">Enter Name :</td>
<td><input type="text" placeholder="Enter user here" id="t1" class="tb" name="name" /></td>
</tr>
<tr>
<td align="right">Enter Email ID :</td>
<td><input type="text" placeholder="Enter Email ID here" id="t2" class="tb" name="email" /></td>
</tr>
<tr>
<td align="right">Enter Username :</td>
<td><input type="text" placeholder="Enter Username here" id="t3" class="tb" name="username" /></td>
</tr>
<tr>
<td align="right">Enter Password :</td>
<td><input type="password" placeholder="Enter Password here" id="t4" class="tb" name="password" /></td>
</tr>
<tr>
<td align="right">Enter Confirm Password :</td>
<td><input type="password" placeholder="Enter Password here" id="t5" class="tb" /></td>
</tr>
<tr>
<td></td>
<td>
<input type="reset" value="Clear Form" id="res" class="btn" />
<input type="submit" value="Create Account" class="btn" name="submit" onclick="registration()" /></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
PHP CODE
<?php
function registNew() {
$con = mysqli_connect("localhost","root","","mydb");
$name = mysqli_real_escape_string($con , $_POST["name"]);
$email = mysqli_real_escape_string($con , $_POST["email"]);
$username = mysqli_real_escape_string($con , $_POST["username"]);
$password = mysqli_real_escape_string($con , $_POST["password"]);
if(mysqli_connect_errno())
{
echo "Error MySQL: " .mysqli_connect_errno();
}
$sqlUser = "SELECT * FROM signup WHERE email = '".$email."'";
$rs = mysqli_query($con ,$sqlUser);
$numUsers = mysqli_num_rows($rs);
if($numUsers > 0) {
?>
<script>
alert("email exists");
</script>
<?php
}
else
{
$newUser= "INSERT INTO signup (name,email,username,password)
VALUES('$name','$email','$username','$password')";
if(mysqli_query($con ,$newUser))
{
?>
<script>
alert("Account created");
</script>
<?php
mysqli_close($con);
header('Location: login.php');
}
else
{
?>
<script>
alert("Error adding user");
</script>
<?php
header("refresh:5;url=signup.php");
}
}
}
?>