Home > Article > Backend Development > How to update database data in PHP
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='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"> <p style='text-align:center;'> <p style='margin:10px;'>员工工号:<input readonly="readonly" name="code" value="<?php echo $att1[0];?>" /></p> <p style='margin:10px;'>员工姓名:<input type="text" name="name" value="<?php echo $att1[1];?>" /></p> <p style='margin:10px;'>出生日期:<input type="text" name="date" value="<?php echo $att1[2];?>"></p> <p style='margin:10px;'>员工年龄:<input type="text" name="age" value="<?php echo $att1[3];?>" /></p> <p style='margin:10px;'>员工职称:<input type="text" name="job" value="<?php echo $att1[4];?>" /></p> <p style='margin:10px;'>所在部门:<input type="text" name="department" value="<?php echo $att1[5];?>"></p> <p style='margin:10px;'>员工月薪:<input type="text" name="month" value="<?php echo $att1[6];?>" /></p> <p style='margin:10px;'>员工年薪:<input type="text" name="year" value="<?php echo $att1[7];?>" /></p> <p style='margin:10px;'>政治面貌:<input type="text" name="politics" value="<?php echo $att1[8];?>"></p> <p style='margin:10px;'>健康状况:<input type="text" name="health" value="<?php echo $att1[9];?>"></p> <p><input type="submit" value="修改数据" /></p> </p> </form> </body>
73a6ac4ed44ffec12cee46588e518a5e
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 姓名='{$name}',出生日期='{$date}',年龄='{$age}',职称='{$job}', 所在部门='{$department}',月薪='{$month}',年薪='{$year}',政治面貌='{$politics}',健康状况='{$health}' where 工号='{$code}'"; $r = $db->query($sql); if($r) { header("location:work.php"); } else { echo "修改失败!"; } ?>
Related recommendations:
Five ways to update the database in thinkphp.
php Solution to update database interruption_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!