第一步创建更新页面文件Upwork.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>删除</title>
</head>
<body>
<h1 style='font-size:18px;text-align:center;'>修改数据</h1>
<?php
$code = $_GET["code"];
$db = new MySQLi("localhost","root","123456","study");
!mysqli_connect_error() or die("连接失败!");
$sql1 = "select * from `员工信息` where 工号='{$code}'";
$r1 = $db->query($sql1);
$att1 = $r1->fetch_row();
?>
<form action="UpworkChuLi.php" method="post">
<div style='text-align:center;'>
<div style='margin:10px;'>员工工号:<input readonly="readonly" name="code" value="<?php echo $att1[0];?>" /></div>
<div style='margin:10px;'>员工姓名:<input type="text" name="name" value="<?php echo $att1[1];?>" /></div>
<div style='margin:10px;'>出生日期:<input type="text" name="date" value="<?php echo $att1[2];?>"></div>
<div style='margin:10px;'>员工年龄:<input type="text" name="age" value="<?php echo $att1[3];?>" /></div>
<div style='margin:10px;'>员工职称:<input type="text" name="job" value="<?php echo $att1[4];?>" /></div>
<div style='margin:10px;'>所在部门:<input type="text" name="department" value="<?php echo $att1[5];?>"></div>
<div style='margin:10px;'>员工月薪:<input type="text" name="month" value="<?php echo $att1[6];?>" /></div>
<div style='margin:10px;'>员工年薪:<input type="text" name="year" value="<?php echo $att1[7];?>" /></div>
<div style='margin:10px;'>政治面貌:<input type="text" name="politics" value="<?php echo $att1[8];?>"></div>
<div style='margin:10px;'>健康状况:<input type="text" name="health" value="<?php echo $att1[9];?>"></div>
<div><input type="submit" value="修改数据" /></div>
</div>
</form>
</body>
</html>
第二步创建更新数据操作的文件UpworkChuLi.php,在Upwork.php中通过表单跳转
<?php
$code = $_POST["code"];
$name = $_POST["name"];
$date = $_POST["date"];
$age = $_POST["age"];
$job = $_POST["job"];
$department = $_POST["department"];
$month = $_POST["month"];
$year = $_POST["year"];
$politics = $_POST["politics"];
$health = $_POST["health"];
$db = new MySQLi("localhost","root","123456","study");
!mysqli_connect_error() or die("连接失败!");
$sql = "update `员工信息` set 姓名='{$name}',出生日期='{$date}',年龄='{$age}',职称='{$job}',
所在部门='{$department}',月薪='{$month}',年薪='{$year}',政治面貌='{$politics}',健康状况='{$health}'
where 工号='{$code}'";
$r = $db->query($sql);
if($r)
{
header("location:work.php");
}
else
{
echo "修改失败!";
}
?>