Simple Project (part-2a)
signUp.php:
.....................................................................................
Then i provide the form's required action.The name of page is signUp_action.php
.....................................................................................
signUp_action.php:
.....................................................................................
Here i create a page for message displaying after successful registration and redirects user to login page.
.....................................................................................
message.php:
<?php
if(isset($error) && $error==true )
{
?>
<center>
<div style="border:1px solid #F00; background-color:#FFF2FF; width:300px;">
<?php
echo $errorMessage;
?>
</div>
</center>
<?php
}
?>
<html>
<link type="text/css" rel="stylesheet" href="style.css"/>
<body>
<div>
<form name="userSignUp" method="post" action="signUp_action.php">
<center>
<table border="0" width="600px" cellpadding="0" cellspacing="0" >
<tr>
<td><h1>User Registration</h1></td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>User Name:
<input name="userName" type="text" id="userName" value="<?php if(isset($_POST['userName'])) echo $_POST['userName']; ?>"/>*
</td>
</tr>
<br>
<tr>
<td>Email:
<input name="userEmail" type="text" id="userEmail" value="<?php if (isset($_POST['userEmail'])) echo $_POST['userEmail']; ?>"/>*
</td>
</tr>
<br>
<tr>
<td>Password:
<input type="password" name="userPassword1" value="">*
</td>
</tr>
<br>
<tr>
<td>Confirm Password:
<input type="password" name="userPassword2" value="">*
</td>
</tr>
<br>
<tr>
<td>
<input type="submit" name="submit" value="Submit"> <input type="reset"
value="Reset">
</td>
</tr>
</table>
</center>
</form>
</div>
</body>
</html>
.....................................................................................
Then i provide the form's required action.The name of page is signUp_action.php
.....................................................................................
signUp_action.php:
<?php
include("connect.php");
//.................................Variable default section...................................
$userName=$_REQUEST['userName'];
$userEmail=$_REQUEST['userEmail'];
$userPassword1=$_POST['userPassword1'];
$userPassword2=$_POST['userPassword2'];
$password=md5($userPassword1);
// .......................Email validation................................
function isValidEmail($userEmail)
{
$pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
if (eregi($pattern, $userEmail))
{
return true;
}
else
{
return false;
}
}
// .......................Error Message................................
$error=false;
$errorMessage="";
if(empty($userName))
{
$error=true;
$userNameError=true;
$errorMessage.="PLease provide username.</br>";
}
if(empty($userEmail))
{
$error=true;
$userEmailError=true;
$errorMessage.="PLease provide email.</br>";
}
if($userPassword1=="")
{
$error=true;
$userPassword1Error=true;
$errorMessage.="PLease provide password.</br>";
}
/*if($userPassword1)
{
if(preg_match("/^.*(?=.{8,})(?=.*[a-z]+)(?=.*[^A-Za-z0-9])(?=.*[0-9\.\-\@\#\$\&]).*$/",$userPassword1))
{
$successMessage.= "Successfuly checked your password.U have to login now";
}
{
$error=true;
$paswordValidationError=true;
$errorMessage.= "Please Enter"."<br />"."Atleast 8 character"."<br />"."Alpha numeric value"."<br />"."1 Special character";
}
}
*/
if($userPassword1!=$userPassword2)
{
$error=true;
$passwordMatchingError=true;
$errorMessage.="Password does not match.</br>";
}
if(!isValidEmail($userEmail))
{
$error=true;
$emailValidationError=true;
$errorMessage.="Invalid email id.</br>";
}
//..............................duplicate email check.........................................................
$query = "SELECT userEmail FROM sign_up WHERE userEmail='" . $userEmail . "'";
$result=mysql_query($query);
$loginFoundEmail = mysql_num_rows($result);
if($loginFoundEmail)
{
$error=true;
$loginFoundEmailError=true;
$errorMessage.="User email is already in use.";
}
//.............................Insert Data...............................
if($error)
{
include("signUp.php");
}
else
{
$sql="insert into sign_up
(
userName,
userEmail,
password
)
values
('$userName','$userEmail','$password')
";
$result=mysql_query($sql);
if($sql)
{
$succes="Successfully inserted";
?>
<script language="javascript">
window.location="message.php";
</script>
<?php
}
}
?>
.....................................................................................
Here i create a page for message displaying after successful registration and redirects user to login page.
.....................................................................................
message.php:
<?php
session_start();
if(!session_is_registered(userName))
{
?>
<script language="javascript">
window.location="userLogin.php";
</script>
<?php
}
?>
<html>
<body>
Login Successful
</body>
</html>
0 Response to "Simple Project (part-2a)"
Post a Comment