UPDATE RECORD INTO DATABASE BY PHP FROM WEBPAGE
1. UPDATE RECORD
(update.php )
<?php
include_once
'database.php';
$result =
mysqli_query($con,"SELECT * FROM emp");
?>
<!DOCTYPE html>
<html>
<head>
<title> Retrive data</title>
<link rel="stylesheet"
href="style.css">
</head>
<body>
<?php
if
(mysqli_num_rows($result) > 0) {
?>
<table>
<tr>EMPLOYEE DETAILS</tr>
<tr>
<td>Emp
No</td>
<td>Emp Name</td>
<td>father Name</td>
<td>City</td>
<td>UPDATE </td>
<td>DELETE </td>
</tr>
<?php
$i=0;
while($row =
mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $row["eid"]; ?></td>
<td><?php echo $row["ename"];
?></td>
<td><?php echo $row["fname"];
?></td>
<td><?php echo $row["city"];
?></td>
<td><a
href="update1.php?eid=<?php echo $row["eid"];
?>">Update</a></td>
<td><a href="delete1.php?eid=<?php
echo $row["eid"]; ?>">Delete</a></td>
</tr>
<?php
$i++;
}
?>
</table>
<?php
}
else
{
echo "No result found";
}
?>
</body>
</html>
(update1.php )
<?php
include_once
'database.php';
if(count($_POST)>0) {
mysqli_query($con,"UPDATE
emp set eid='" . $_POST['eid'] . "', ename='" . $_POST['ename']
. "', fname='" . $_POST['fname'] . "', city='" .
$_POST['city'] . "' WHERE eid='" . $_POST['eid'] . "'");
$message = "Record
Modified Successfully";
}
$result =
mysqli_query($con,"SELECT * FROM emp WHERE eid='" . $_GET['eid'] .
"'");
$row=
mysqli_fetch_array($result);
?>
<html>
<head>
<title>Update
Employee Data</title>
</head>
<body>
<form
name="frmUser" method="post" action="">
<div><?php
if(isset($message)) { echo $message; } ?>
</div>
<div
style="padding-bottom:5px;">
<a
href="retrieve.php">Employee List</a>
</div>
Username: <br>
<input
type="hidden" name="eid" class="txtField"
value="<?php echo $row['eid']; ?>">
<input
type="text" name="eid"
value="<?php echo $row['eid']; ?>">
<br>
Employ Name: <br>
<input
type="text" name="ename" class="txtField"
value="<?php echo $row['ename']; ?>">
<br>
Father Name :<br>
<input
type="text" name="fname" class="txtField"
value="<?php echo $row['fname']; ?>">
<br>
City:<br>
<input
type="text" name="city" class="txtField"
value="<?php echo $row['city']; ?>">
<br>
<input type="submit"
name="submit" value="Submit" class="buttom">
</form>
</body>
</html>
0 Comments