Home >>MySQL Tutorial >PHP MySQL Secure Registration Page

PHP MySQL Secure Registration Page

Create Registration Form PHP MySQL

Registration page is basically a page having several fields that the user provide in order to get register themselves for that site. Registration page contains various details about user , that user had to fill Some fields are mandatory and some are optional. We can apply several validations on registration page using java-script on clicking submit button all the information for that particular user are stored in the database. For every new user he need to register himself and for existing users he just need to login. In above example there are 4 fields: name , password , mobile number , gender if these fields are found to be empty it will show error. if the existing user try to register with same information then error is reported.

Create Database and Table

<?php
//First create a database test
$con=mysqli_connect("localhost","root","","test") or die(mysqli_error());

//create table stuinfo inside test database
$que="CREATE TABLE userinfo
 (
user_id INT  AUTO_INCREMENT PRIMARY KEY ,
user_name VARCHAR( 50 ) NOT NULL ,
password VARCHAR( 50 ) NOT NULL ,
mobile BIGINT NOT NULL ,
gender ENUM( 'm', 'f' ) NOT NULL ,
)";
mysqli_query($con,$que);
?>

PHP Script

<?php
if(isset($_POST['reg']))
{
if($_POST['un']=="" || $_POST['pwd']=="" $_POST['mob']=="")
{	
$err="fill your user name first";	
}
else
{
$r=mysqli_query($con,"SELECT * FROM userinfo where user_name='{$_POST['un']}'");
$t=mysqli_num_rows($r);
if($t)
{
$err="user already exists choose another";
}
else
{
mysqli_query($con,"INSERT INTO userinfo values('','{$_POST['un']}','{$_POST['pwd']}','{$_POST['mob']}','{$_POST['gen']}')");
header('location:https://www.phptpoint.com');	
}
}
}
?>

Registration Form(HTML Script)

<form method="post" enctype="multipart/form-data">
<table width="438" border="5" align="center">
  <font color="#FF0000"><?php echo $err; ?></font>
  <tr>
    <td width="204" height="47">Enter Your User Name </td>
    <td width="218"><input type="text" name="un"/></td>
  </tr>
  <tr>
    <td height="39">Enter Your Password </td>
    <td><input type="password" name="pwd"/></td>
  </tr>
  <tr>
    <td height="47">Enter Your Mobile </td>
    <td><input type="text" name="mob"/></td>
  </tr>
  <tr>
    <td height="33">Select Your Gender </td>
    <td>
		Male<input type="radio" name="gen" value="m"/>
		Female<input type="radio" name="gen" value="f"/>	</td>
  </tr>
  <tr>
    <td align="center" colspan="2">
	<input type="submit" name="reg" value="Register"/>
	<input type="reset"  value="Reset"/>	</td>
  </tr>
</table>
</form>
In above example there are 4 feilds: name , password , mobile number , gender if these feilds are found to be empty it will show error. if the existing user try to register with same information then error is reported.

No Sidebar ads