First of all create HTML Design to take the value of the record like no (recommended Primary Key Field) with the following code:
edit.html
<html>
<head>
</head>
<body>
<form action=edit.php method=POST>
Enter no<input type=text name=n>
<input type=submit value=EDIT>
</form>
</body>
</html>
Afterward, create edit.php file to check if the value entered by the user exists or not.......If the value exists then display that record in editable format or if not exists then display appropriate message as follows:
edit.php
<?php
$no=$_POST['n'];
$cn=mysql_connect("localhost","root") or die(mysql_error());
$db=mysql_select_db("sybca",$cn) or die(mysql_error());
$row=mysql_query("select * from student where no=$no",$cn) or die(mysql_error());
$n=mysql_num_rows($row);
if($n<=0)
{
echo "Record not found";
exit;
}
else
{
$data=mysql_fetch_row($row);
echo "<form action=update.php method=POST>";
echo "No<input type=text value=$data[0] name=no>";
echo "<br> Name<input type=text value=$data[1] name=nm>";
echo "<br> City<input type=text value=$data[2] name=ct>";
echo "<input type=submit value=UPDATE>";
echo "<br><input type=hidden value=$no name=oldno>";
echo "</form>";
}
?>
After this, if record found, it will be displayed in editable format. U can make the changes as per your need in any of the fields. Then when you will click on Update button, the record will be updated in the database.. for that you have to create another file update.php as follows:
update.php
<?php
$no=$_POST['no'];
$nm=$_POST['nm'];
$ct=$_POST['ct'];
$old=$_POST['oldno'];
$cn=mysql_connect("localhost","root");
$db=mysql_select_db("sybca",$cn);
mysql_query("update student set no=$no,name='$nm',city='$ct' where no=$old",$cn);
echo "Record Updated";
?>
edit.html
<html>
<head>
</head>
<body>
<form action=edit.php method=POST>
Enter no<input type=text name=n>
<input type=submit value=EDIT>
</form>
</body>
</html>
Afterward, create edit.php file to check if the value entered by the user exists or not.......If the value exists then display that record in editable format or if not exists then display appropriate message as follows:
edit.php
<?php
$no=$_POST['n'];
$cn=mysql_connect("localhost","root") or die(mysql_error());
$db=mysql_select_db("sybca",$cn) or die(mysql_error());
$row=mysql_query("select * from student where no=$no",$cn) or die(mysql_error());
$n=mysql_num_rows($row);
if($n<=0)
{
echo "Record not found";
exit;
}
else
{
$data=mysql_fetch_row($row);
echo "<form action=update.php method=POST>";
echo "No<input type=text value=$data[0] name=no>";
echo "<br> Name<input type=text value=$data[1] name=nm>";
echo "<br> City<input type=text value=$data[2] name=ct>";
echo "<input type=submit value=UPDATE>";
echo "<br><input type=hidden value=$no name=oldno>";
echo "</form>";
}
?>
After this, if record found, it will be displayed in editable format. U can make the changes as per your need in any of the fields. Then when you will click on Update button, the record will be updated in the database.. for that you have to create another file update.php as follows:
update.php
<?php
$no=$_POST['no'];
$nm=$_POST['nm'];
$ct=$_POST['ct'];
$old=$_POST['oldno'];
$cn=mysql_connect("localhost","root");
$db=mysql_select_db("sybca",$cn);
mysql_query("update student set no=$no,name='$nm',city='$ct' where no=$old",$cn);
echo "Record Updated";
?>
Nice blog sir......
ReplyDelete