Tuesday, March 18, 2014

Registration Form PHP Souce Codes

Hello, PHP lovers!
Today, we are going to see some simple php codes by which you can complete a registration using MySQL database and interface by HTML CSS.

First have a  visit at DonorsDB.com Registration Page



I am going to show you the behind codes of that page at here.

For this You have to have a database table named `usertab` where the columns are like `id`, `name`, `bgroup`, `bplace`, `phone`, `email`, `password`, `occupation`, `work`, `regdate`, `caddress`, `paddress`, `do`, `fb`, `tw`, `religion`, `about` will be appeared.

then, in db.php page we are going to keep the PHP MySQL database connection information.

Here comes the registration page codes:
<?php
if(isset($_POST['bgroup'])){

include('./db.php');

$name = htmlentities(mysql_real_escape_string($_POST['name']));
$bgroup = $_POST['bgroup'];
$bplace = htmlentities(mysql_real_escape_string($_POST['bplace']));
$phone = htmlentities(mysql_real_escape_string($_POST['phone']));
$email = htmlentities(mysql_real_escape_string($_POST['email']));
$password = htmlentities(md5(mysql_real_escape_string($_POST['password'])));
$occupation = htmlentities(mysql_real_escape_string($_POST['occupation']));
$work = htmlentities(mysql_real_escape_string($_POST['work']));
$dat = date("d-m-Y");
$caddress = htmlentities(mysql_real_escape_string($_POST['caddress']));
$paddress = htmlentities(mysql_real_escape_string($_POST['paddress']));
$do = htmlentities(mysql_real_escape_string($_POST['do']));
$fb = htmlentities(mysql_real_escape_string($_POST['fb']));
$tw = htmlentities(mysql_real_escape_string($_POST['tw'])); 
$religion = htmlentities(mysql_real_escape_string($_POST['religion']));
$about = htmlentities(mysql_real_escape_string($_POST['about']));


if( $bgroup=="nobg") {
echo "<br>Invalid Bloog Group!";
break;
}
else  {
$qry = mysql_query("SELECT * FROM usertab where email='$email'");
if(mysql_num_rows($qry)>0) die("This User already exists in DonorsDB");

else{
$qu = mysql_query("INSERT INTO usertab (`id`, `name`, `bgroup`, `bplace`, `phone`, `email`, `password`, `occupation`, `work`, `regdate`, `caddress`, `paddress`, `do`, `fb`, `tw`, `religion`, `about`)
VALUES (id,'$name','$bgroup','$bplace','$phone','$email','$password','$occupation','$work','$dat','$caddress','$paddress','$do','$fb','$tw','$religion','$about')");

if(!$qu) die("DonorDB Error is ".mysql_error());
else {
echo "<br>Registration Successful, Login Here";
header( "refresh:2; url= index.php" );
}
}


}
}
?>

Hope you enjoyed and implemented the process. Definitely it's going to work for you, if doesn't then don't feel shy to have  a comment below in comment field. 

If you are planning to make a big users management system for your users, contact with my team at HERE!

1 comment: