Registration Form

<!-- save as registration.php-->

<?php
error_reporting(0);
include("config.php");


$firstName=trim($_POST['txtFirstName']);
$middleName=trim($_POST['txtMiddleName']);
$lastName=trim($_POST['txtLastName']);
$username=trim($_POST['txtUsername']);
$password=trim($_POST['txtPassword']);
$txtReTypePassword=trim($_POST['txtReTypePassword']);
$sex=$_POST['sex'];
$txtPLocation=$_POST['txtPLocation'];
$txtAreaAddress=trim($_POST['txtAreaAddress']);
$txtSTDNo=trim($_POST['txtSTDNo']);
$txtPhoneNo=trim($_POST['txtPhoneNo']);
$txtCountryCode=trim($_POST['txtCountryCode']);
$txtMobileNo=trim($_POST['txtMobileNo']);
$selectState=$_POST['selectState'];
$selectCity=$_POST['selectCity'];
$txtCountry=trim($_POST['txtCountry']);


if(isset($_POST['btnSubmit']) && ($_POST['btnSubmit']=="Register Me"))
{

if(empty($firstName))
{
$strError[] .="<li>Please Enter First Name</li>";
}
if(empty($middleName))
{
$strError[] .="<li>Please Enter Middle Name</li>";
}
if(empty($lastName))
{
$strError[] .="<li>Please Enter Last Name</li>";
}
if(empty($username))
{
$strError[] .="<li>Please Enter Username</li>";
}
if(empty($password))
{
$strError[] .="<li>Please Enter Password</li>";
}
if(empty($txtReTypePassword))
{
$strError[] .="<li>Please Re-Type Password</li>";
}
if(empty($sex))
{
$strError[] .="<li>Please Select Sex</li>";
}
if(empty($txtPLocation))
{
$strError[] .="<li>Please Select Preffered Location</li>";
}
if(empty($txtAreaAddress))
{
$strError[] .="<li>Please Enter Address</li>";
}
if(empty($txtSTDNo))
{
$strError[] .="<li>Please Enter STD Code</li>";
}
if(empty($txtPhoneNo))
{
$strError[] .="<li>Please Enter Phone No</li>";
}
if(empty($txtCountryCode))
{
$strError[] .="<li>Please Enter Country Code</li>";
}
if(empty($txtMobileNo))
{
$strError[] .="<li>Please Enter Mobile No</li>";
}
if(empty($selectState))
{
$strError[] .="<li>Please Select State</li>";
}
if(empty($selectCity))
{
$strError[] .="<li>Please Select City</li>";
}
if(empty($txtCountry))
{
$strError[] .="<li>Please Enter Country</li>";
}
if($password != $txtReTypePassword)
{
$strError[] .="<li>Password is not matched</li>";
}
if(!empty($firstName) && !empty($middleName) && !empty($lastName) && !empty($username) && !empty($password) && !empty($txtReTypePassword) && !empty($sex) && !empty($txtPLocation) && !empty($txtAreaAddress) && !empty($txtSTDNo) && !empty($txtPhoneNo) && !empty($txtCountryCode) && !empty($txtMobileNo) && !empty($selectState) && !empty($selectCity) && !empty($txtCountry))
   {
$mysqlSelect = "SELECT * FROM tbl_admin WHERE username='".$username."'";
$mysqlSelected = mysql_query($mysqlSelect);

$count = mysql_num_rows($mysqlSelected);

if($count > 0)
{
$strError[] .= "<li> Username is already exist </li>";
}
else if($password == $txtReTypePassword)
{
$encodedPassword=base64_encode($password);
$txtPrefLocation=implode(",",$txtPLocation);

$mysqlInsertRUser = "INSERT INTO registered_user
(
firstname,
middlename,
lastname,
username,
password,
sex,
preflocation,
address,
stdcode,
phoneno,
countrycode,
mobileno,
state_id,
city_id,
country
)
VALUES
(
'".addslashes($firstName)."',
'".addslashes($middleName)."',
'".addslashes($lastName)."',
'".addslashes($username)."',
'".$encodedPassword."',
'".$sex."',
'".$txtPrefLocation."',
'".addslashes($txtAreaAddress)."',
'".addslashes($txtSTDNo)."',
'".addslashes($txtPhoneNo)."',
'".addslashes($txtCountryCode)."',
'".addslashes($txtMobileNo)."',
'".$selectState."',
'".$selectCity."',
'".addslashes($txtCountry)."'
)";

$mysqlInsertedRUser = mysql_query($mysqlInsertRUser);

$mysqlInsertAdmin = "INSERT INTO tbl_admin
(
username,
password
)
VALUES
(
'".addslashes($username)."',
'".$encodedPassword."'
)";

$mysqlInsertedAdmin = mysql_query($mysqlInsertAdmin);

header('Location: registered.php');
}
}
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registration Form</title>
<link type="text/css" href="css/style.css" rel="stylesheet" />
</head>
<body>
<div id="regiheading">Registration Form
</div>
<div id="regiwrap" align="center">
<table width="620px" border="0" cellpadding="0" cellspacing="0">
<tr>
<td id="regileftcorntop">
</td>
<td id="regiupperstrip">
</td>
<td id="regirightcorntop">
</td>
</tr>
<tr>
<td colspan="3">
<form name="registrationFrm" action="" method="post" id="registrationID" enctype="multipart/form-data" target="">
<div align="center">
<table border="0" width="620" cellspacing="0" cellpadding="5" align="center">
<tr>
<td id="sideborder">
</td>
<td>
</td>
<td>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td colspan="2" style="color:#FF0000; padding-left:100px;">
<?php foreach($strError as $key => $val)
 {  
echo $val;

 } 
?>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">First Name : 
</td>
<td id="namefields"><input type="text" name="txtFirstName" id="txtFirstNameId" value="<?php echo $firstName; ?>" size="35"/>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">Middle Name : 
</td>
<td id="namefields"><input type="text" name="txtMiddleName" id="txtMiddleNameId" value="<?php echo $middleName; ?>" size="35"/>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">Last Name : 
</td>
<td id="namefields"><input type="text" name="txtLastName" id="txtLastNameId" value="<?php echo $lastName; ?>" size="35"/>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">Username : 
</td>
<td id="namefields"><input type="text" name="txtUsername" id="txtUsernameId" value="<?php echo $username; ?>" size="35"/>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">Password : 
</td>
<td id="namefields"><input type="password" name="txtPassword" id="txtPasswordId" value="" size="35"/>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">Re-Type Password : 
</td>
<td id="namefields"><input type="password" name="txtReTypePassword" id="txtReTypePasswordId" value="" size="35"/>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">Gender : 
</td>
<td id="namefields"><input type="radio" name="sex" id="sexId" value="Male" <?php if($sex=='Male') echo 'checked'; ?>/>Male<span><input type="radio" name="sex" id="sexId" value="Female" <?php if($sex=='Female') echo 'checked'; ?>/>Female</span>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">Prefferd Location : 
</td>
<td id="namefields"><input type="checkbox" name="txtPLocation[]" id="txtPLocationId" value="Sydney" <?php if($txtPLocation[0]=="Sydney" || $txtPLocation[1]=="Sydney" || $txtPLocation[1]=="Sydney") echo 'checked'; ?>>Sydney<span><input type="checkbox" name="txtPLocation[]" id="txtPLocationId" value="Ottawa" <?php if($txtPLocation[0]=="Ottawa" || $txtPLocation[1]=="Ottawa" || $txtPLocation[2]=="Ottawa") echo 'checked'; ?>>Ottawa</span><span><input type="checkbox" name="txtPLocation[]" id="txtPLocationId" value="Singapore" <?php if($txtPLocation[0]=="Singapore" || $txtPLocation[1]=="Singapore" || $txtPLocation[2]=="Singapore") echo 'checked' ; ?>>Singapore</span>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">Address : 
</td>
<td id="namefields"><textarea cols="27" rows="5" name="txtAreaAddress" wrap=yes id="txtAreaAddressID"><?php echo $txtAreaAddress; ?></textarea>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">Phone Number : 
</td>
<td id="namefields"><input type="text" name="txtSTDNo" id="txtSTDNoId" size="4" value="<?php echo $_POST['txtSTDNo'] ?>" />-<input type="text" name="txtPhoneNo" id="txtPhoneNoId" size="26" value="<?php echo $_POST['txtPhoneNo'] ?>" />
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td>
</td>
<td style="font-size:12px;">STD Code<span style="margin-left:50px;">Phone Number</span>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">Mobile Number : 
</td>
<td id="namefields"><input type="text" name="txtCountryCode" value="+91" size="4"  maxlength="3" />-<input type="text" name="txtMobileNo" id="txtMobileNoId" size="26" value="<?php echo $_POST['txtMobileNo'] ?>" />
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">State : 
</td>
<td id="namefields"><select name="selectState" style="width:239px;">
<option value="0">--- Select State ---</option>
<?php
$state=mysql_query("select * from tbl_state");
while($data=mysql_fetch_array($state))
{
$state_id=$data['state_id'];
$state_name=$data['state_name'];
?>
<option value="<?Php echo $state_id; ?>" <?php if($_POST['selectState']==$state_id)echo 'selected'?>><?Php echo $state_name; ?>
</option>
<?php } ?>
</select>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">City : 
</td>
<td id="namefields"><select name="selectCity" style="width:239px;">
<option value="0">---- Select City ----</option>
<?php
$city=mysql_query("select * from tbl_city");
while($data=mysql_fetch_array($city))
{
$city_id=$data['city_id'];
$city_name=$data['city_name'];
?>
<option value="<?Php echo $city_id; ?>" <?php if($_POST['selectCity']==$city_id) echo 'selected'?>><?Php echo $city_name; ?>
</option>
<?php } ?>
</select>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">Country : 
</td>
<td id="namefields"><input type="text" name="txtCountry" id="txtCountryId" size="35" value="<?php echo $_POST['txtCountry'] ?>" />
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td>
</td>
<td>
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td id="namelabel">
</td>
<td id="namefields"><input type="submit" name="btnSubmit" value="Register Me" />
</td>
<td id="sideborder">
</td>
</tr>
<tr>
<td id="sideborder">
</td>
<td>
</td>
<td>
</td>
<td id="sideborder">
</td>
</tr>
</table>
</div>
</form>
</tr>
<tr>
<td id="regileftcornbot">
</td>
<td id="regilowerstrip">
</td>
<td id="regirightcornbot">
</td>
</tr>
</table>
</div>
</body>
</html>