Simple Project(part-3b)

.......................................................................................

In this section i create a page for creation for user profile .

.......................................................................................


profile.php



<script language="javascript">
function displayDiv(id)
{
document.getElementById(id).style.display='';
}
function hideDiv()
{
document.getElementById("pofile").style.display='none';
}

</script>

<?php
include("connect.php");
if(isset ($error) && $error==true)

{
?>
<center>
<div style="border:1px solid #F00; background-color:#FFF2FF; width:300px;">
<?php
echo $errorMessage;
?>
</div>
</center>
<?php
}

?>

<?php if(isProfileCreated()==1)
{

?>
<script language="javascript">
window.location="viewMyProfile.php";
</script>
<?php
}

else
{

?>

<a href="javascript:displayDiv('pofile')">Create Profile</a>


<link type="text/css" rel="stylesheet" href="style.css"/>
<div id="pofile" <?php if(!$error) {?> style="display:none;" <?php }?>>
<form name="userCreateProfile" method="post" action="profile_action.php">
<center>
<div ><h3>Create Profile</h3>
<div>Name:
<input name="userName" type="text" value="<?php if(isset($_POST['userName'])) echo $_POST['userName']; ?>"id="Name">*
</div>

</br>
<div>Father's Name:
<input name="userfatherName" type="text" value="<?php if(isset($_POST['userfatherName'])) echo $_POST['userfatherName'];?>" id="fatherName">*
</div>

</br>
<div>Occupation:
<input name="userOccupation" type="text" value="<?php if(isset($_POST['userOccupation'])) echo $_POST['userOccupation']; ?>" id="Occupation">*
</div>

</br>
<div>Nationality:
<input name="userNationality" type="text" value="<?php if(isset($_POST['userNationality'])) echo $_POST['userNationality']; ?>" id="Nationality">*
</div>
</br>
<div>Religion:
<input name="userReligion" type="text" value="<?php if(isset($_POST['userReligion'])) echo $_POST['userReligion']; ?>" id="Religion">*
</div>
</br>

<div>Address:
<textarea rows="10" cols="35" name="userAddress">
</textarea>
</div>
</br>
<div>Designation:
<input name="userDesignation" type="text" value="<?php if(isset($_POST['userDesignation'])) echo $_POST['userDesignation']; ?>" id="Designation">*
</div>
</br>
<div>Country:
<?php $query="SELECT COUNTRY_ID, COUNTRY from countrys where ISACTIVE=1 ORDER BY COUNTRY";
$result=mysql_query($query);

?>

<select name="country" >
<option value="" >Select a country</option>
<?php while($country =mysql_fetch_array($result))
{
?>
<option value="<?php echo $country['COUNTRY_ID'];?>" <?php if($country['COUNTRY_ID']==$_REQUEST['country']) echo 'selected';?> > <?php echo $country['COUNTRY'];?></option>
<?php
}
?>
</select>

</br>
</br>
<input name="Create" type="submit" value="Create"/><input name="Reset" type="Reset" value="Reset"/>
<input name="Cancel" onClick="hideDiv()" type="button" value="Cancel"/>
</div>

</div>

</center>
</form>

</div>
<div id="gallery" style="display:none;">Gallery</div>
<?php
}
function isProfileCreated()
{
$query="select userName from create_profile where userid='{$_SESSION['id']}'";
$result=mysql_query($query);
$val= mysql_num_rows($result);

return $val;
}

?>

..........................................................................................................................................................................

profile_action.php



<?php
session_start();
include("connect.php");

//..........................get values from from.........................................................//

$userName=$_REQUEST['userName'];
$userfatherName = $_REQUEST['userfatherName'];
$userOccupation = $_REQUEST['userOccupation'];
$userNationality = $_REQUEST['userNationality'];
$userReligion = $_REQUEST['userReligion'];
$userAddress = $_REQUEST['userAddress'];
$userDesignation = $_REQUEST['userDesignation'];
$Country=$_REQUEST['country'];

// .......................Error Message................................

$error=false;
$errorMessage="";

if(empty($userName))
{
$error=true;
$userNameError=true;
$errorMessage.="Please provide username.</br>";
}
if(empty($userfatherName))
{
$error=true;
$userfatherNameError=true;
$errorMessage.="Please provide Father's name.</br>";
}
if(empty($userNationality))
{
$error=true;
$userNationalityError=true;
$errorMessage.="Please provide Nationality.</br>";
}
if(empty($userReligion ))
{
$error=true;
$userReligionNameError=true;
$errorMessage.="Please provide Religion.</br>";
}
if(empty($userDesignation))
{
$error=true;
$userDesignationNameError=true;
$errorMessage.="Please provide Designation.</br>";
}
/*if(empty($country))
{
$error=true;
$countryError=true;
$errorMessage.="Please select country</br>";
}*/

//..........................insert data .........................................................//
if($error)

{

include("profile.php");
}
else
{
$sql="
INSERT into create_profile
(
userid,
userName,
userfatherName,
userOccupation,
userNationality,
userReligion,
userAddress,
userDesignation,
country
)
values

('$_SESSION[id]','$userName','$userfatherName','$userOccupation','$userNationality','$userReligion','$userAddress','$userDesignation','$Country')

";
$result=mysql_query($sql);
$id=mysql_insert_id();
if($result)
{


?>
<script language="javascript">
window.location="viewMyProfile.php?id=<?php echo $id;?>";
</script>
<?php
}

}
?>

0 Response to "Simple Project(part-3b)"

Post a Comment

powered by Blogger | WordPress by Newwpthemes | Converted by BloggerTheme