How to update database data in PHP

小云云
Release: 2023-03-20 22:56:02
Original
10291 people have browsed it

This article mainly shares with you how to update database data in PHP. Hope it helps everyone.

The first step is to create the update page file Upwork.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>删除</title>
</head>
<body>
<h1 style=&#39;font-size:18px;text-align:center;&#39;>修改数据</h1>
Copy after login
  <?php
  $code = $_GET["code"];
  $db = new MySQLi("localhost","root","123456","study");
  !mysqli_connect_error() or die("连接失败!");
  $sql1 = "select * from `员工信息` where 工号=&#39;{$code}&#39;";
  $r1 = $db->query($sql1);
  $att1 = $r1->fetch_row();
 ?>
 <form action="UpworkChuLi.php" method="post">
 <p style=&#39;text-align:center;&#39;>
     <p style=&#39;margin:10px;&#39;>员工工号:<input readonly="readonly" name="code" value="<?php echo $att1[0];?>" /></p>
     <p style=&#39;margin:10px;&#39;>员工姓名:<input type="text" name="name" value="<?php echo $att1[1];?>" /></p>
<p style=&#39;margin:10px;&#39;>出生日期:<input type="text" name="date" value="<?php echo $att1[2];?>"></p>
<p style=&#39;margin:10px;&#39;>员工年龄:<input type="text" name="age" value="<?php echo $att1[3];?>" /></p>
     <p style=&#39;margin:10px;&#39;>员工职称:<input type="text" name="job" value="<?php echo $att1[4];?>" /></p>
<p style=&#39;margin:10px;&#39;>所在部门:<input type="text" name="department" value="<?php echo $att1[5];?>"></p>
<p style=&#39;margin:10px;&#39;>员工月薪:<input type="text" name="month" value="<?php echo $att1[6];?>" /></p>
     <p style=&#39;margin:10px;&#39;>员工年薪:<input type="text" name="year" value="<?php echo $att1[7];?>" /></p>
<p style=&#39;margin:10px;&#39;>政治面貌:<input type="text" name="politics" value="<?php echo $att1[8];?>"></p>
<p style=&#39;margin:10px;&#39;>健康状况:<input type="text" name="health" value="<?php echo $att1[9];?>"></p>
    
     <p><input type="submit" value="修改数据" /></p>
</p>
 </form>
</body>
Copy after login


The second step is to create the update data operation file UpworkChuLi.php, Jump through the form in 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 姓名=&#39;{$name}&#39;,出生日期=&#39;{$date}&#39;,年龄=&#39;{$age}&#39;,职称=&#39;{$job}&#39;,
 所在部门=&#39;{$department}&#39;,月薪=&#39;{$month}&#39;,年薪=&#39;{$year}&#39;,政治面貌=&#39;{$politics}&#39;,健康状况=&#39;{$health}&#39; 
 where 工号=&#39;{$code}&#39;";
 $r = $db->query($sql);
 if($r)
 {
     header("location:work.php");
 }
 else
 {
     echo "修改失败!";
 }
?>
Copy after login

Related recommendations:

Five ways to update the database in thinkphp.

php Solution to update database interruption_PHP tutorial

php+mysqli uses object-oriented method to update database instance, mysqli object-oriented_PHP Tutorial

The above is the detailed content of How to update database data in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!