第一步建立添加数据页面addwork.php
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<title>添加</title>
</head>
<body>
<h1 style='font-size:18px;text-align:center;'>添加数据</h1>
<form action="addworkChuLi.php" method="post">
<div style='text-align:center;'>
<div style='margin:10px;'>员工工号:<input type="text" name="code" /></div>
<div style='margin:10px;'>员工姓名:<input type="text" name="name" /></div>
<div style='margin:10px;'>出生日期:<input type="text" name="date" /></div>
<div style='margin:10px;'>员工年龄:<input type="text" name="age"></div>
<div style='margin:10px;'>员工职称:<input type="text" name="job"></div>
<div style='margin:10px;'>所在部门:<input type="text" name="department"></div>
<div style='margin:10px;'>员工月薪:<input type="text" name="month"></div>
<div style='margin:10px;'>员工年薪:<input type="text" name="year"></div>
<div style='margin:10px;'>政治面貌:<input type="text" name="politics"></div>
<div style='margin:10px;'>健康状况:<input type="text" name="health"></div>
<div style='margin:10px;'><input type="submit" value="添加数据" /></div>
</div>
</form>
</body>
</html>
第二步建立添加数据处理操作的文件addWorkChuLi.php
<?php
error_reporting(0);
$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 = "insert into `员工信息` values('{$code}','{$name}','{$date}',
'{$age}','{$job}','{$department}','{$month}','{$year}','{$politics}','{$health}')";
$result = $db->query($sql);
if($result)
{
header("location:work.php");
}
else
{
echo "添加失败!";
}
?>