//This is HTML Form Code
<?php
session_start();
include("err_report.php");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link href="styler.css" rel="stylesheet" type="text/css">
<link href="err_styler.css" rel="stylesheet" type="text/css">
<title>Greens Registration</title>
<style>
label
{
color:#F00;
padding-right:5px;
}
.err_username
{
visibility:<?php echo $er_uname ?>;
}
.err_pw
{
visibility:<?php echo $er_pw ?>;
}
.err_cpw
{
visibility:<?php echo $er_cpw ?>;
}
.err_email
{
visibility:<?php echo $er_email ?>;
}
</style>
</head>

<body>
<?php
include("header.php");
?>
<br/><br/>
<div class="reg">
<h2>User Registration</h2>
<h5>All are mandatory fields</h5>
<form action="reg.php" method="post" autocomplete="on">
<ul>
<li><label class="err_username">*</label><input class="uinput" type="text" name="username" id="username" autofocus autocomplete="on" placeholder="Username" maxlength="20"></li>
<li><label class="err_pw">*</label><input class="uinput" type="password" name="pw" id="pw" placeholder="Password" maxlength="20">
</li>
<li><label class="err_cpw">*</label><input class="uinput" type="password" name="cpw" id="cpw" placeholder="Confirm Password" ></li>
<li><label class="err_email">*</label><input class="uinput" type="text" name="email" id="email" placeholder="E-Mail"></li>
<li>
<input type="radio" checked value="Domestic" name="userdi">
Domestic
<input type="radio" value="International" name="userdi">
International
</li>
<li><input type="submit" value="Register" class="regBtn"></li>

</ul>
</form>
</div>
</body>
</html>


//This is PHP5 Form validation code

<?php
session_start();

$con = mysqli_connect("localhost","root","","mydb") or die("Error: Database not connected...");

$uname = "";
$pw = "";
$cpw = "";
$eml = "";
$di = $_POST["userdi"];
$err = "";
//Username validation
if(filter_has_var(INPUT_POST, "username"))
{
echo("Username not entered...");
$err = "err";
$_SESSION['er_uname']="err";
}
else
{
if (!filter_input(INPUT_POST, "username", FILTER_SANITIZE_STRING))
{
echo "Username is not valid";
$err = "err";
$_SESSION['er_uname']="err";
}
else
{
$uname = base64_encode($_POST["username"]);
}
}

//PASSWORD validation
if(filter_has_var(INPUT_POST,"pw"))
{
echo("Password not entered...");
$err = "err";
$_SESSION['er_pw']="err";
}
else
{
if (!filter_input(INPUT_POST, "pw", FILTER_SANITIZE_STRING))
{
echo "Password is not valid";
$err = "err";
$_SESSION['er_pw']="err";
}
else
{
$pw = base64_encode($_POST["pw"]);

}
}

//PASSWORD confirm validation
if(filter_has_var(INPUT_POST, "cpw"))
{
echo("Password confirmaton not entered...");
$err = "err";
$_SESSION['er_cpw']="err";
}
else
{
if (!filter_input(INPUT_POST,"cpw", FILTER_SANITIZE_STRING))
{
echo "Password confirmation is not valid";
$err = "err";
$_SESSION['er_cpw']="err";
}
else
{
if($_POST["cpw"]==$_POST["pw"])
{
$cpw = base64_encode($_POST["cpw"]);
}
else
{
echo "Password confirmation is not match";
$err = "err";
$_SESSION['er_cpw']="err";
}
}
}

//Email validation
if(filter_has_var(INPUT_POST, "email"))
{
echo("Email not entered...");
$err = "err";
$_SESSION['er_email']="err";
}
else
{
if (filter_input(INPUT_POST, "email", FILTER_SANITIZE_EMAIL))
{
if (filter_input(INPUT_POST, "email", FILTER_VALIDATE_EMAIL))
{
$eml = $_POST["email"];
}
else
{
echo "E-Mail is not valid";
$err = "err";
$_SESSION['er_email']="err";
}
}

}

if($err != "err")
{
$qry = "INSERT INTO dbuser VALUES('','$uname','$pw','$eml','$di')";

mysqli_query($con,$qry) or die("cannot execute the query");
echo "user registered";
/*
$to = "admin@gmail.com";
$subject = "Greens Registration";
$msg = "You have applied for registration with Greens";
mail($to,$subject,$msg);
*/
session_destroy();
}
else
{
//header('location:registeruser.php');
}
?>