Monday 10 September 2012

Simple Registration Page with Database Connectivity in HTML and PHP: Part 2


<?php

$getuser=$_POST['username'];
$getemail=$_POST['email'];
$getpwd=$_POST['password'];
$getpassword=$_POST['cnfpwd'];
$getname=$_POST['fullName'];


if(strlen($getemail>=7)&&(strstr($getemail,"@")&&(strstr($getemail,"."))))
{
require("connection.php");
$query=mysql_query("SELECT * FROM registeration WHERE username='$getuser'");
$numrows=mysql_num_rows($query);
if($numrows==0)
{
$query=mysql_query("SELECT * FROM registeration WHERE email='$getemail'");
$numrows=mysql_num_rows($query);
if($numrows==0)
{
$code=rand(11111111,99999999);
mysql_query("INSERT INTO registeration(fullName,age,gender,DOB,address,phone,qualification,workExperience,Institute,email,username,maritalStatus,expertise,password,active,code,date) VALUES ('$_POST[fullName]','$_POST[age]','$_POST[gender]','$_POST[DOB]','$_POST[address]','$_POST[phone]','$_POST[qualification]','$_POST[workExperience]','$_POST[Institute]','$_POST[email]','$_POST[username]','$_POST[maritalStatus]','$_POST[expertise]','$_POST[password]','0','$code',SYSDATE())");
$query=mysql_query("SELECT * FROM registeration WHERE username='$getuser'");
$numrows=mysql_num_rows($query);
if($numrows==1)
{
$site="http://localhost/projectname";
$webmaster="abc@xyz.com";
$headers="From: $webmaster";
$subject="Activate Your Account";
$message="Hello $getuser \n\nThank you for registring with us .click the link to activate your account";
$message.="$site/activate.php?code=$code\n";
$message.="You must activate your account to login";
if(mail($getemail,$subject,$message,$hearders))
{
echo"you have been registered";
$getuser="";
$getemail="";
$getpwd="";
$getpassword="";
}
else
echo"An error occoured .your activation email was not sent";
}
else
echo"an error occured";
}
else
echo"There is already an user with that email";
}
}
else
echo"you must enter a valid email address";


?>

connection.php



<?php
mysql_connect("localhost","username","password");
mysql_select_db("databasename");
?>

No comments:

Post a Comment