PHP向数据库插入数据

第一步建立添加数据页面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 "添加失败!";
}
?>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值