<?php
include("./connect.php");
if(isset($_POST['btnReg'])){
$name=$_POST['txtnm'];
$gen=$_POST['rdbgen'];
$cno=$_POST['txtcno'];
$addr=$_POST['txtaddr'];
$h=$_POST['chk'];
$desg=$_POST['selDesg'];
$hobby=implode(",",$h);
$sql="insert into tblPerson(pname,gender,contactNo,hobbies,address,designation) values('".$name."','".$gen."','".$cno."','".$hobby."','".$addr."','".$desg."')";
$res=mysqli_query($con,$sql);
}
if(isset($_POST['btnDisp'])){
header("Location:./disp.php");
}
if(isset($_GET['act'])){
$sql="select * from tblPerson where pid =".$_GET['id'];
$res=mysqli_query($con,$sql);
$row=mysqli_fetch_array($res);
$hobby=explode(",",$row['hobbies']);
$desg=$row['designation'];
}
if(isset($_POST['btnUpd'])){
echo 'upd';
$name=$_POST['txtnm'];
$gen=$_POST['rdbgen'];
$cno=$_POST['txtcno'];
$addr=$_POST['txtaddr'];
$h=$_POST['chk'];
$desg=$_POST['selDesg'];
$hobby=implode(",",$h);
$sql="update tblPerson set pname='".$name."',gender='".$gen."',contactNo='".$cno."',hobbies='".$hobby."',address='".$addr."',designation='".$desg."' where pid=".$_GET['id'];
$res=mysqli_query($con,$sql);
}
?>
<!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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post">
<table width="779" border="1" cellspacing="0" cellpadding="10">
<tr>
<th scope="row">Name :</th>
<td><input type="text" name="txtnm" id="txtnm" value="<?php (isset($row))? print($row[1]):print("") ?>" /></td>
</tr>
<tr>
<th scope="row">Gender :</th>
<td>
<?php
if(isset($row)){
if(strcmp($row['gender'],"Male")==0){
?>
<input type="radio" name="rdbgen" value="Male" checked="checked" />
Male
<input type="radio" name="rdbgen" value="Female" />
Female
<?php
}
else{
?>
<input type="radio" name="rdbgen" value="Male" />
Male
<input type="radio" name="rdbgen" value="Female" checked="checked"/>
Female
<?php
}
}
else{
?>
<input type="radio" name="rdbgen" value="Male" />
Male
<input type="radio" name="rdbgen" value="Female"/>
Female
<?php
}
?>
</td>
</tr>
<tr>
<th scope="row">Contact No. :</th>
<td><input type="text" name="txtcno" id="txtcno" value="<?php (isset($row))? print($row['contactNo']):print("") ?>" /></td>
</tr>
<tr>
<th scope="row">Address :</th>
<td><textarea name="txtaddr" id="txtaddr" cols="45" rows="5"><?php (isset($row))? print($row['address']):print("") ?></textarea></td>
</tr>
<tr>
<th scope="row">Hobbies :</th>
<td>
<?php
$hb=array("Dancing","Sports","Singing");
if(isset($row)){
$j=0;
foreach($hb as $val){
if(strcmp($hobby[$j],$val)==0){
echo "<input type='checkbox' name='chk[]' value='".$val."' checked='checked' />".$val."<br/>";
$j++;
}
else{
echo "<input type='checkbox' name='chk[]' value='".$val."' />".$val."<br/>";
}
}
}
else{
foreach($hb as $val){
echo "<input type='checkbox' name='chk[]' value='".$val."' />".$val."<br/>";
}
}
?>
</td>
</tr>
<tr>
<th scope="row">Designation :</th>
<td><select name="selDesg">
<?php
$ch=array('Programmer','Project Manager','Analyst','Clerk');
foreach($ch as $c){
if(isset($row) && strcmp($c,$desg)==0){
?>
<option value="<?php echo $c; ?>" selected="selected"><?php echo $c; ?></option>
<?php
}
else{
?>
<option value="<?php echo $c; ?>"><?php echo $c; ?></option>
<?php
}
}
?>
</select></td>
</tr>
<tr>
<th colspan="2" scope="row"><input type="submit" name="<?php (isset($row))? print("btnUpd"):print("btnReg")?>" value="<?php (isset($row))? print("Update"):print("Register Me") ?>" />
<input type="submit" name="btnDisp" value="Display" />
</th>
</tr>
</table>
</form>
</body>
</html>
include("./connect.php");
if(isset($_POST['btnReg'])){
$name=$_POST['txtnm'];
$gen=$_POST['rdbgen'];
$cno=$_POST['txtcno'];
$addr=$_POST['txtaddr'];
$h=$_POST['chk'];
$desg=$_POST['selDesg'];
$hobby=implode(",",$h);
$sql="insert into tblPerson(pname,gender,contactNo,hobbies,address,designation) values('".$name."','".$gen."','".$cno."','".$hobby."','".$addr."','".$desg."')";
$res=mysqli_query($con,$sql);
}
if(isset($_POST['btnDisp'])){
header("Location:./disp.php");
}
if(isset($_GET['act'])){
$sql="select * from tblPerson where pid =".$_GET['id'];
$res=mysqli_query($con,$sql);
$row=mysqli_fetch_array($res);
$hobby=explode(",",$row['hobbies']);
$desg=$row['designation'];
}
if(isset($_POST['btnUpd'])){
echo 'upd';
$name=$_POST['txtnm'];
$gen=$_POST['rdbgen'];
$cno=$_POST['txtcno'];
$addr=$_POST['txtaddr'];
$h=$_POST['chk'];
$desg=$_POST['selDesg'];
$hobby=implode(",",$h);
$sql="update tblPerson set pname='".$name."',gender='".$gen."',contactNo='".$cno."',hobbies='".$hobby."',address='".$addr."',designation='".$desg."' where pid=".$_GET['id'];
$res=mysqli_query($con,$sql);
}
?>
<!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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post">
<table width="779" border="1" cellspacing="0" cellpadding="10">
<tr>
<th scope="row">Name :</th>
<td><input type="text" name="txtnm" id="txtnm" value="<?php (isset($row))? print($row[1]):print("") ?>" /></td>
</tr>
<tr>
<th scope="row">Gender :</th>
<td>
<?php
if(isset($row)){
if(strcmp($row['gender'],"Male")==0){
?>
<input type="radio" name="rdbgen" value="Male" checked="checked" />
Male
<input type="radio" name="rdbgen" value="Female" />
Female
<?php
}
else{
?>
<input type="radio" name="rdbgen" value="Male" />
Male
<input type="radio" name="rdbgen" value="Female" checked="checked"/>
Female
<?php
}
}
else{
?>
<input type="radio" name="rdbgen" value="Male" />
Male
<input type="radio" name="rdbgen" value="Female"/>
Female
<?php
}
?>
</td>
</tr>
<tr>
<th scope="row">Contact No. :</th>
<td><input type="text" name="txtcno" id="txtcno" value="<?php (isset($row))? print($row['contactNo']):print("") ?>" /></td>
</tr>
<tr>
<th scope="row">Address :</th>
<td><textarea name="txtaddr" id="txtaddr" cols="45" rows="5"><?php (isset($row))? print($row['address']):print("") ?></textarea></td>
</tr>
<tr>
<th scope="row">Hobbies :</th>
<td>
<?php
$hb=array("Dancing","Sports","Singing");
if(isset($row)){
$j=0;
foreach($hb as $val){
if(strcmp($hobby[$j],$val)==0){
echo "<input type='checkbox' name='chk[]' value='".$val."' checked='checked' />".$val."<br/>";
$j++;
}
else{
echo "<input type='checkbox' name='chk[]' value='".$val."' />".$val."<br/>";
}
}
}
else{
foreach($hb as $val){
echo "<input type='checkbox' name='chk[]' value='".$val."' />".$val."<br/>";
}
}
?>
</td>
</tr>
<tr>
<th scope="row">Designation :</th>
<td><select name="selDesg">
<?php
$ch=array('Programmer','Project Manager','Analyst','Clerk');
foreach($ch as $c){
if(isset($row) && strcmp($c,$desg)==0){
?>
<option value="<?php echo $c; ?>" selected="selected"><?php echo $c; ?></option>
<?php
}
else{
?>
<option value="<?php echo $c; ?>"><?php echo $c; ?></option>
<?php
}
}
?>
</select></td>
</tr>
<tr>
<th colspan="2" scope="row"><input type="submit" name="<?php (isset($row))? print("btnUpd"):print("btnReg")?>" value="<?php (isset($row))? print("Update"):print("Register Me") ?>" />
<input type="submit" name="btnDisp" value="Display" />
</th>
</tr>
</table>
</form>
</body>
</html>
No comments:
Post a Comment