PHP更新数据库数据

第一步创建更新页面文件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 "修改失败!";
 }
?>

 



  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值