Update Inserted Data into table using Php
Update Inserted Data into table using Php with backend:
Code(update.php):-
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("exam");
$id=$_POST['id'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$dob=$_POST['dob'];
$org=$_POST['org'];
$dst=$_POST['dst'];
$country=$_POST['country'];
$state=$_POST['state'];
$city=$_POST['city'];
$query="update tblpersons set id='$id',firstname='$fname',lastname='$lname',doj='$dob',organization='$org',designation='$dst',countryid='$country',state='$state',
city='$city' where id=".$id."";
$q=mysql_query($query,$con);
if($q)
{
echo "sucess";
}
else
{
echo "unsuccess";
}
mysql_close($con);
header("location:show.php");
echo "update successfully..";
?>
updaterecord.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=utf-8" />
<title>Update record</title>
</head>
<body>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("exam");
$id=$_GET['id'];
$sql="select * from tblpersons where id=".$id."";
$result=mysql_query($sql,$con);
while($row=mysql_fetch_array($result))
{
$id=$row['id'];
$fname=$row['firstname'];
$lname=$row['lastname'];
$dob=$row['doj'];
$org=$row['organization'];
$dst=$row['designation'];
$country=$row['countryid'];
$state=$row['state'];
$city=$row['city'];
}
?>
<form method="post" action="update.php">
<fieldset>
<legend>Personal Information</legend>
<p>
Id:
<input type="text" value="<?php echo $id; ?>" name="id" />
<br/><br/>
select Person:
<select name="fname">
<?php
$q1=mysql_query("select * from tblpersons");
while($r1=mysql_fetch_array($q1))
{
echo "<option value='".$r1['id']."'>".$r1['firstname'].$r1['lastname']."</option>";
$id=$r1['id'];
$fname=$r1['firstname'];
$lname=$r1['lastname'];
$dob=$r1['doj'];
$org=$r1['organization'];
$dst=$r1['designation'];
$country=$r1['countryid'];
$state=$r1['state'];
$city=$r1['city'];
}
?>
</select>
</br>
</br>
firstname:
<input type="text" value="<?php echo $fname; ?>" name="fname" />
<br/><br/>
lastname:
<input type="text" value="<?php echo $lname; ?>" name="lname" />
<br/><br/>
Date of birth:
<input type="date" value="<?php echo $dob; ?>" name="dob" />
<br/><br/>
organization:
<input type="text" value="<?php echo $org; ?>" name="org" />
<br/>
<br/>
designation:
<input type="text" value="<?php echo $dst; ?>" name="dst" />
<br/>
<br/>
country:
<select name="country">
<?php
$q1=mysql_query("select * from tbllocations");
while($r1=mysql_fetch_array($q1))
{
echo "<option value='".$r1['id']."'>".$r1['name']."</option>";
}
?>
</select>
</br>
</br>
state:
<input type="text" value="<?php echo $state; ?>" name="state" />
<br/>
<br/>
city:
<input type="text" value="<?php echo $city; ?>" name="city" />
<br/><br/>
<input type="submit" value="save" />
<input type="reset" value="cancle" />
</fieldset>
</p>
</form>
<?php
mysql_close($con);
?>
</body>
</html>
Comments
Post a Comment