新建文件

This commit is contained in:
2025-01-06 19:52:30 +08:00
commit 4d2d5e2d5e
32 changed files with 1177 additions and 0 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

8
.idea/20250103.iml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/20250103.iml" filepath="$PROJECT_DIR$/.idea/20250103.iml" />
</modules>
</component>
</project>

20
.idea/php.xml generated Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MessDetectorOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCSFixerOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PHPCodeSnifferOptionsConfiguration">
<option name="highlightLevel" value="WARNING" />
<option name="transferred" value="true" />
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.0" />
<component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" />
</component>
<component name="PsalmOptionsConfiguration">
<option name="transferred" value="true" />
</component>
</project>

4
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings" defaultProject="true" />
</project>

17
acl_list.php Normal file
View File

@ -0,0 +1,17 @@
<?php
// 定义 ACL 表
$acl = array(
"cto" => array("r_1.php", "r_2.php", "r_3.php"),
"manager" => array("r_2.php", "r_3.php"),
"staff" => array("r_3.php")
);
// 定义检查权限的函数
function checkAccess($role, $resource) {
global $acl;
if (isset($acl[$role]) && in_array($resource, $acl[$role])) {
return true; // 有权限
}
return false; // 无权限
}

38
api_183_1.php Normal file
View File

@ -0,0 +1,38 @@
<?php
// 获取参数
$student_id = $_GET['student_id'] ?? null;
$english = $_GET['english'] ?? null;
$math = $_GET['math'] ?? null;
$computer = $_GET['computer'] ?? null;
// 校验参数是否完整
if ($student_id === null || $english === null || $math === null || $computer === null) {
// 返回错误信息
echo json_encode([
"error" => "Missing required parameters: student_id, english, math, computer"
]);
exit;
}
// 验证分数是否为数字
if (!is_numeric($english) || !is_numeric($math) || !is_numeric($computer)) {
// 返回错误信息
echo json_encode([
"error" => "Parameters english, math, and computer must be numeric"
]);
exit;
}
// 计算总分
$sum = $english + $math + $computer;
// 封装为 JSON 格式
$response = [
"student_id" => $student_id,
"sum" => (string)$sum // 转为字符串以匹配返回格式
];
// 输出 JSON
header('Content-Type: application/json');
echo json_encode($response);
?>

38
api_183_2.php Normal file
View File

@ -0,0 +1,38 @@
<?php
// 获取参数
$student_id = $_GET['student_id'] ?? null;
$english = $_GET['english'] ?? null;
$math = $_GET['math'] ?? null;
$computer = $_GET['computer'] ?? null;
// 校验参数是否完整
if ($student_id === null || $english === null || $math === null || $computer === null) {
// 返回错误信息
echo json_encode([
"error" => "Missing required parameters: student_id, english, math, computer"
]);
exit;
}
// 验证分数是否为数字
if (!is_numeric($english) || !is_numeric($math) || !is_numeric($computer)) {
// 返回错误信息
echo json_encode([
"error" => "Parameters english, math, and computer must be numeric"
]);
exit;
}
// 计算最高分
$max = max($english, $math, $computer);
// 封装为 JSON 格式
$response = [
"student_id" => $student_id,
"max" => (string)$max // 转为字符串以匹配返回格式
];
// 输出 JSON
header('Content-Type: application/json');
echo json_encode($response);
?>

102
create_tables.php Normal file
View File

@ -0,0 +1,102 @@
<?php
include_once "db_config.php";
// 创建数据库连接
$conn = $link;
// 检查连接是否成功
if ($conn->connect_error) {
die("数据库连接失败: " . $conn->connect_error);
}
// 设置字符集
$conn->set_charset("utf8");
// 创建患者表
$sql_patient = "
CREATE TABLE IF NOT EXISTS patient_90 (
patient_id CHAR(50),
patient_name CHAR(50),
patient_gender CHAR(1),
patient_address CHAR(50)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
";
if ($conn->query($sql_patient) === TRUE) {
echo "患者表创建成功!<br>";
} else {
echo "创建患者表失败: " . $conn->error . "<br>";
}
// 创建医生表
$sql_doctor = "
CREATE TABLE IF NOT EXISTS doctor_90 (
doctor_id CHAR(50),
doctor_name CHAR(50),
doctor_gender CHAR(1),
department_id CHAR(50)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
";
if ($conn->query($sql_doctor) === TRUE) {
echo "医生表创建成功!<br>";
} else {
echo "创建医生表失败: " . $conn->error . "<br>";
}
// 创建科室表
$sql_department = "
CREATE TABLE IF NOT EXISTS department_90 (
department_id CHAR(50),
department_name CHAR(50),
department_location CHAR(50)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
";
if ($conn->query($sql_department) === TRUE) {
echo "科室表创建成功!<br>";
} else {
echo "创建科室表失败: " . $conn->error . "<br>";
}
// 创建挂号表
$sql_register = "
CREATE TABLE IF NOT EXISTS register_90 (
biz_id CHAR(50),
doctor_id CHAR(50),
patient_id CHAR(50),
register_date INT,
fee INT,
state CHAR(1)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
";
if ($conn->query($sql_register) === TRUE) {
echo "挂号表创建成功!<br>";
} else {
echo "创建挂号表失败: " . $conn->error . "<br>";
}
// 插入测试数据
$sql_insert = "
INSERT IGNORE INTO patient_90 (patient_id, patient_name, patient_gender, patient_address) VALUES
('510103001', '张三', '1', '成都'),
('510103002', '李四', '2', '重庆');
INSERT IGNORE INTO doctor_90 (doctor_id, doctor_name, doctor_gender, department_id) VALUES
('510105001', '王医生', '2', '001'),
('510105002', '罗医生', '1', '002'),
('510105003', '陈医生', '1', '001');
INSERT IGNORE INTO department_90 (department_id, department_name, department_location) VALUES
('001', '内科', '1楼2诊室'),
('002', '外科', '1楼5诊室');
";
if ($conn->multi_query($sql_insert) === TRUE) {
echo "测试数据插入成功!<br>";
} else {
echo "插入测试数据失败: " . $conn->error . "<br>";
}
// 关闭数据库连接
$conn->close();
?>

7
db_config.php Normal file
View File

@ -0,0 +1,7 @@
<?php
$link=mysqli_connect('localhost','user_20250103_58056','0PHoN2YsWaQdSJY','exam_20250103_58056');
mysqli_query($link,'set names utf8');
// 设置默认时区
date_default_timezone_set("Asia/Shanghai");

43
form_test_2.php Normal file
View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>表单编程与现场恢复</title>
</head>
<body>
<?php
// 定义变量用于回显数据
$name = "";
$password_md5 = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// 获取提交的姓名和密码
$name = isset($_POST['name']) ? htmlspecialchars($_POST['name']) : "";
$password = isset($_POST['password']) ? $_POST['password'] : "";
// 使用 MD5 对密码进行加密
$password_md5 = md5($password);
}
?>
<!-- 表单 -->
<form action="form_test_2.php" method="post">
<label for="name">姓名:</label>
<input type="text" id="name" name="name" value="<?php echo $name; ?>">
<br><br>
<label for="password">密码:</label>
<input type="password" id="password" name="password" value="">
<br><br>
<input type="submit" id="ok" name="ok" value="提交">
</form>
<!-- 输出提交结果 -->
<?php if ($_SERVER["REQUEST_METHOD"] == "POST"): ?>
<h3>提交结果:</h3>
<p>姓名:<?php echo $name; ?></p>
<p>处理后的密码:<?php echo $password_md5; ?></p>
<?php endif; ?>
</body>
</html>

79
form_test_74_2.php Normal file
View File

@ -0,0 +1,79 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>表单提交与现场恢复</title>
</head>
<body>
<?php
// 定义变量,用于回显用户输入的数据
$name = "";
$gender = "";
$courses = [];
$hometown = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// 获取表单数据
$name = isset($_POST['name']) ? htmlspecialchars($_POST['name']) : "";
$gender = isset($_POST['gender']) ? $_POST['gender'] : "";
$courses = isset($_POST['course']) ? $_POST['course'] : [];
$hometown = isset($_POST['hometown']) ? $_POST['hometown'] : "";
}
?>
<!-- 表单 -->
<form action="form_test_74_2.php" method="post">
<!-- 姓名 -->
<label for="name">姓名:</label>
<input type="text" id="name" name="name" value="<?php echo $name; ?>">
<br><br>
<!-- 性别 -->
性别:
<input type="radio" id="male" name="gender" value="1" <?php echo ($gender == "1") ? "checked" : ""; ?>>
<label for="male">男</label>
<input type="radio" id="female" name="gender" value="2" <?php echo ($gender == "2") ? "checked" : ""; ?>>
<label for="female">女</label>
<br><br>
<!-- 选课 -->
选课:
<input type="checkbox" id="computer" name="course[]" value="computer" <?php echo in_array("computer", $courses) ? "checked" : ""; ?>>
<label for="computer">计算机</label>
<input type="checkbox" id="math" name="course[]" value="math" <?php echo in_array("math", $courses) ? "checked" : ""; ?>>
<label for="math">数学</label>
<input type="checkbox" id="english" name="course[]" value="english" <?php echo in_array("english", $courses) ? "checked" : ""; ?>>
<label for="english">英语</label>
<br><br>
<!-- 籍贯 -->
籍贯:
<select id="hometown" name="hometown">
<option value="beijing" <?php echo ($hometown == "beijing") ? "selected" : ""; ?>>北京</option>
<option value="chengdu" <?php echo ($hometown == "chengdu") ? "selected" : ""; ?>>成都</option>
<option value="chongqing" <?php echo ($hometown == "chongqing") ? "selected" : ""; ?>>重庆</option>
</select>
<br><br>
<!-- 提交按钮 -->
<input type="submit" id="ok" name="ok" value="提交">
</form>
<!-- 输出提交结果 -->
<?php if ($_SERVER["REQUEST_METHOD"] == "POST"): ?>
<h3>提交结果:</h3>
<p>姓名:<?php echo $name; ?></p>
<p>性别:<?php echo ($gender == "1") ? "男" : (($gender == "2") ? "女" : "未选择"); ?></p>
<p>选课:
<?php
if (!empty($courses)) {
echo implode("", $courses);
} else {
echo "未选择";
}
?>
</p>
<p>籍贯:<?php echo !empty($hometown) ? $hometown : "未选择"; ?></p>
<?php endif; ?>
</body>
</html>

97
list_72.php Normal file
View File

@ -0,0 +1,97 @@
<?php
require_once "db_config.php"; // 引入数据库配置文件
$conn = $link;
// 每页显示的记录数
$limit = 10;
// 获取当前的action和offset参数
$action = isset($_GET['action']) ? $_GET['action'] : 'top';
$offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
// 获取总记录数
$sql_count = "SELECT COUNT(*) AS total FROM user_70";
$result_count = $conn->query($sql_count);
$total_records = $result_count->fetch_assoc()['total'];
// 计算总页数
$total_pages = ceil($total_records / $limit);
// 根据action计算新的offset
switch ($action) {
case 'top':
$offset = 0;
break;
case 'previous':
$offset = max(0, $offset - $limit);
break;
case 'next':
$offset = min($total_records - $limit, $offset + $limit);
break;
case 'bottom':
$offset = max(0, ($total_pages - 1) * $limit);
break;
default:
$offset = 0;
break;
}
// 查询当前页的数据
$sql = "SELECT name FROM user_70 LIMIT $offset, $limit";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>姓名列表</title>
<style>
table {
width: 300px;
border-collapse: collapse;
margin: 20px auto;
}
th, td {
border: 1px solid #000;
text-align: center;
padding: 8px;
}
a {
margin: 0 5px;
text-decoration: none;
color: blue;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<table>
<tr>
<th>姓名列表</th>
</tr>
<?php
// 输出数据
if ($result->num_rows > 0) {
$index = $offset + 1; // 起始序号
while ($row = $result->fetch_assoc()) {
echo "<tr><td>{$index}. {$row['name']}</td></tr>";
$index++;
}
} else {
echo "<tr><td>没有数据</td></tr>";
}
?>
<tr>
<td>
<a href="list_72.php?action=top&offset=0">首页</a>
<a href="list_72.php?action=previous&offset=<?php echo $offset; ?>">上一页</a>
<a href="list_72.php?action=next&offset=<?php echo $offset; ?>">下一页</a>
<a href="list_72.php?action=bottom&offset=<?php echo ($total_pages - 1) * $limit; ?>">末页</a>
</td>
</tr>
</table>
</body>
</html>

52
login.php Normal file
View File

@ -0,0 +1,52 @@
<?php
session_start(); // 启用 Session
require_once "db_config.php"; // 引入数据库配置
$conn = $link;
// 检查是否提交表单
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$password = isset($_POST['password']) ? trim($_POST['password']) : '';
if (empty($name) || empty($password)) {
echo "姓名和密码不能为空!";
} else {
// 将密码转换为 MD5 格式
$hashedPassword = md5($password);
// 查询用户信息
$sql = "SELECT * FROM user_70 WHERE name = ? AND password = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss", $name, $hashedPassword);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// 登录成功,设置 Session
$_SESSION['s_name'] = $name;
header("Location: user_info.php"); // 跳转到 user_info.php
exit();
} else {
// 登录失败
echo "用户名或密码错误!";
}
}
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>用户登录</title>
</head>
<body>
<form method="POST" action="login.php">
<label for="name">姓名:</label>
<input type="text" id="name" name="name"><br>
<label for="password">密码:</label>
<input type="password" id="password" name="password"><br>
<button type="submit" id="ok" name="ok">提交</button>
</form>
</body>
</html>

114
patient_register_90.php Normal file
View File

@ -0,0 +1,114 @@
<?php
include "db_config.php";
date_default_timezone_set("Asia/Shanghai");
$conn = $link;
// 生成UUID函数
function generateUUID() {
return bin2hex(random_bytes(16));
}
// 初始化变量
$patient_id = $doctor_id = $fee = "";
$register_date = date("Y-m-d");
$message = "";
// 提交表单处理
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$patient_id = $_POST["patient_id"];
$doctor_id = $_POST["doctor_id"];
$fee = empty($_POST["fee"]) ? 10 : (int)$_POST["fee"]; // 默认挂号费为10元
$current_date = strtotime($register_date);
// 检查同一患者当天是否已挂号
$sql_check = "SELECT * FROM register_90 WHERE patient_id = '$patient_id' AND register_date = $current_date";
$result_check = $conn->query($sql_check);
if ($result_check->num_rows > 0) {
// 更新挂号信息
$sql_update = "UPDATE register_90 SET doctor_id = '$doctor_id', fee = $fee, state = '1' WHERE patient_id = '$patient_id' AND register_date = $current_date";
if ($conn->query($sql_update)) {
$message = "挂号信息已更新!";
} else {
$message = "更新失败: " . $conn->error;
}
} else {
// 插入新挂号记录
$biz_id = generateUUID();
$sql_insert = "INSERT INTO register_90 (biz_id, doctor_id, patient_id, register_date, fee, state) VALUES ('$biz_id', '$doctor_id', '$patient_id', $current_date, $fee, '1')";
if ($conn->query($sql_insert)) {
$message = "挂号成功!";
} else {
$message = "挂号失败: " . $conn->error;
}
}
}
// 获取患者列表
$sql_patients = "SELECT patient_id, patient_name FROM patient_90";
$result_patients = $conn->query($sql_patients);
// 获取医生和科室列表
$sql_doctors = "
SELECT doctor_90.doctor_id, doctor_90.doctor_name, department_90.department_name
FROM doctor_90
JOIN department_90 ON doctor_90.department_id = department_90.department_id";
$result_doctors = $conn->query($sql_doctors);
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>患者挂号</title>
</head>
<body>
<h2>患者挂号</h2>
<form action="patient_register_90.php" method="post">
<!-- 患者选择 -->
<label for="patient_id">选择患者:</label>
<select id="patient_id" name="patient_id">
<?php if ($result_patients->num_rows > 0): ?>
<?php while ($row = $result_patients->fetch_assoc()) { ?>
<option value="<?php echo $row['patient_id']; ?>" <?php echo ($patient_id == $row['patient_id']) ? "selected" : ""; ?>>
<?php echo $row['patient_name']; ?>
</option>
<?php } ?>
<?php else: ?>
<option value="">暂无患者数据</option>
<?php endif; ?>
</select>
<br><br>
<!-- 医生选择 -->
<label for="doctor_id">选择医生:</label>
<select id="doctor_id" name="doctor_id">
<?php if ($result_doctors->num_rows > 0): ?>
<?php while ($row = $result_doctors->fetch_assoc()) { ?>
<option value="<?php echo $row['doctor_id']; ?>" <?php echo ($doctor_id == $row['doctor_id']) ? "selected" : ""; ?>>
<?php echo $row['doctor_name'] . "|" . $row['department_name']; ?>
</option>
<?php } ?>
<?php else: ?>
<option value="">暂无医生数据</option>
<?php endif; ?>
</select>
<br><br>
<!-- 挂号时间 -->
<label for="register_date">挂号时间:</label>
<input type="text" id="register_date" name="register_date" value="<?php echo $register_date; ?>" readonly>
<br><br>
<!-- 挂号费 -->
<label for="fee">挂号费:</label>
<input type="text" id="fee" name="fee" value="<?php echo $fee; ?>">
<br><br>
<!-- 提交按钮 -->
<input type="submit" id="ok" name="ok" value="确定">
</form>
<p><?php echo $message; ?></p>
</body>
</html>

View File

@ -0,0 +1,107 @@
<?php
include "db_config.php";
date_default_timezone_set("Asia/Shanghai");
$conn = $link;
// 初始化变量
$search_field = isset($_POST["search_field"]) ? $_POST["search_field"] : "doctor";
$search_value = isset($_POST["search_value"]) ? $_POST["search_value"] : "";
$message = "";
// 查询挂号信息
$sql_query = "
SELECT
department_90.department_name,
doctor_90.doctor_name,
patient_90.patient_name,
FROM_UNIXTIME(register_90.register_date, '%Y-%m-%d') AS register_date,
register_90.fee,
register_90.biz_id
FROM register_90
JOIN doctor_90 ON register_90.doctor_id = doctor_90.doctor_id
JOIN department_90 ON doctor_90.department_id = department_90.department_id
JOIN patient_90 ON register_90.patient_id = patient_90.patient_id";
if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($search_value)) {
if ($search_field == "doctor") {
$sql_query .= " WHERE doctor_90.doctor_name LIKE '%$search_value%'";
} elseif ($search_field == "patient") {
$sql_query .= " WHERE patient_90.patient_name LIKE '%$search_value%'";
}
}
$result = $conn->query($sql_query);
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>患者挂号列表</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
}
th {
background-color: #f2f2f2;
}
tr:hover {
background-color: #f5f5f5;
}
</style>
</head>
<body>
<h2>患者挂号列表</h2>
<form action="patient_register_list_90.php" method="post">
<label for="search_field">查询条件:</label>
<select id="search_field" name="search_field">
<option value="doctor" <?php echo ($search_field == "doctor") ? "selected" : ""; ?>>医生</option>
<option value="patient" <?php echo ($search_field == "patient") ? "selected" : ""; ?>>患者</option>
</select>
=
<input type="text" id="search_value" name="search_value" value="<?php echo htmlspecialchars($search_value); ?>">
<input type="submit" id="ok" name="ok" value="确定">
</form>
<hr>
<table>
<thead>
<tr>
<th>科室</th>
<th>医生</th>
<th>患者</th>
<th>就诊时间</th>
<th>挂号费</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php if ($result && $result->num_rows > 0): ?>
<?php while ($row = $result->fetch_assoc()) { ?>
<tr>
<td><?php echo $row["department_name"]; ?></td>
<td><?php echo $row["doctor_name"]; ?></td>
<td><?php echo $row["patient_name"]; ?></td>
<td><?php echo $row["register_date"]; ?></td>
<td><?php echo $row["fee"]; ?></td>
<td>
<a href="edit_register_90.php?biz_id=<?php echo $row['biz_id']; ?>">编辑</a>
|
<a href="delete_register_90.php?biz_id=<?php echo $row['biz_id']; ?>" onclick="return confirm('确定要删除此记录吗?');">删除</a>
</td>
</tr>
<?php } ?>
<?php else: ?>
<tr>
<td colspan="6" style="text-align: center;">暂无数据</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</body>
</html>

14
r_1.php Normal file
View File

@ -0,0 +1,14 @@
<?php
// 引入 ACL 文件
include 'acl_list.php';
// 获取角色参数
$role = $_GET['role'] ?? null;
// 检查权限
if ($role && checkAccess($role, 'r_1.php')) {
echo "欢迎光临";
} else {
echo "无权访问";
}
?>

9
r_2.php Normal file
View File

@ -0,0 +1,9 @@
<?php
include 'acl_list.php';
$role = $_GET['role'] ?? null;
if ($role && checkAccess($role, 'r_2.php')) {
echo "欢迎光临";
} else {
echo "无权访问";
}
?>

8
r_3.php Normal file
View File

@ -0,0 +1,8 @@
<?php
include 'acl_list.php';
$role = $_GET['role'] ?? null;
if ($role && checkAccess($role, 'r_3.php')) {
echo "欢迎光临";
} else {
echo "无权访问";
}

73
register.php Normal file
View File

@ -0,0 +1,73 @@
<?php
include_once "db_config.php";
$conn = $link;
// 检查连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 检查是否提交表单
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$password = isset($_POST['password']) ? trim($_POST['password']) : '';
// 表单验证
if (empty($name) || empty($password)) {
echo "姓名和密码不能为空!";
} else {
// 密码加密
$hashedPassword = md5($password);
// 查询是否存在该用户
$sql = "SELECT * FROM user_70 WHERE name = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $name);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// 用户存在,更新密码
$updateSql = "UPDATE user_70 SET password = ? WHERE name = ?";
$updateStmt = $conn->prepare($updateSql);
$updateStmt->bind_param("ss", $hashedPassword, $name);
if ($updateStmt->execute()) {
echo "密码更新成功!";
} else {
echo "密码更新失败:" . $conn->error;
}
} else {
// 用户不存在,插入新用户
$insertSql = "INSERT INTO user_70 (name, password) VALUES (?, ?)";
$insertStmt = $conn->prepare($insertSql);
$insertStmt->bind_param("ss", $name, $hashedPassword);
if ($insertStmt->execute()) {
echo "注册成功!";
} else {
echo "注册失败:" . $conn->error;
}
}
}
}
// 关闭数据库连接
$conn->close();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>用户注册与修改密码</title>
</head>
<body>
<form method="POST" action="register.php">
<label for="name">姓名:</label>
<input type="text" id="name" name="name"><br>
<label for="password">密码:</label>
<input type="password" id="password" name="password"><br>
<button type="submit" id="ok" name="ok" value="ok">提交</button>
</form>
</body>
</html>

5
robot_251_1.php Normal file
View File

@ -0,0 +1,5 @@
<?php
$content = file_get_contents("http://125.64.9.222:8022/goods/flash_sale.php");
$pattern = '/\d+(?=元)/';
preg_match_all($pattern, $content, $matches);
echo "[".$matches[0][0]."]";

50
setup.html Normal file
View File

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>操作表</title>
<!-- 确保 jQuery 库正确加载 -->
<script src="http://125.64.9.222:8022/public_libs/jquery.js"></script>
<script>
// 确保在文档加载完成后执行
$(document).ready(function(operation, table) {
function query(operation, table) {
$.ajax({
url: "/setup.php",
type: "POST",
data: {
operation: operation,
table: table
}
}).done((res) => {
console.log(res)
// 检查并使用返回的JSON数据
$("#result").html(res);
}).fail((jqXHR, textStatus, errorThrown) => {
$('#result').html('Request failed: ' + textStatus);
});
}
// 按钮点击事件绑定
$('button').click(function() {
const operation = $(this).attr('data-operation');
const table = $('#mySelect').val()
query(operation, table);
});
});
</script>
</head>
<body>
<button data-operation="del">drop table</button>
<button data-operation="create">create table</button>
<button data-operation="select">select table</button>
<select id="mySelect">
<option value="user_70">user_70</option>
<option value="nucleic_acid_test_2">nucleic_acid_test_2</option>
<option value="patient_90">patient_90</option>
</select>
<button onclick="location.reload();">refresh</button>
<div id="result" style="border: 1px solid; margin-top:15px; margin-left: 20px; margin-right: 100px; padding: 50px">
</div>
</body>
</html>

118
setup.php Normal file
View File

@ -0,0 +1,118 @@
<?php
session_start();
include_once("db_config.php");
mysqli_set_charset($link, 'utf8');
$table = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$operation = $_POST['operation'];
$table = $_POST['table'];
if ($operation == 'del') {
drop_table($link, $table);
} else if ($operation == 'create') {
create_table($link, $table);
} else {
select_table($link, $table);
}
}
function drop_table($link, $table){
$query_string = "drop table if exists $table";
mysqli_query($link,$query_string);
echo "表删除成功";
}
function create_table($link, $table){
$result = mysqli_query($link,"show tables like '$table' ");
if ($result && mysqli_num_rows($result) > 0) {
$tableExist = true;
}else{
$tableExist = false;
}
if(!$tableExist){
if($table == 'user_70'){
$query_string = "create table user_70(name char(50),address char(50),password char(50))ENGINE=MyISAM DEFAULT CHARSET=utf8";
mysqli_query($link,$query_string);
$query_string = "insert into user_70(name,address,password)values('mike','chengdu','c4ca4238a0b923820dcc509a6f75849b')";
mysqli_query($link,$query_string);
$query_string = "insert into user_70(name,address,password)values('mike','beijing','c4ca4238a0b923820dcc509a6f75849b')";
mysqli_query($link,$query_string);
$query_string = "insert into user_70(name,address,password)values('tom','chengdu','c4ca4238a0b923820dcc509a6f75849b')";
mysqli_query($link,$query_string);
$query_string = "insert into user_70(name,address,password)values('rose','chengdu','c4ca4238a0b923820dcc509a6f75849b')";
mysqli_query($link,$query_string);
}
else if($table == 'nucleic_acid_test_2'){
$eventTime=mktime(12,12,12,12,12,2022);
$query_string = "create table nucleic_acid_test_2(id varchar(50),name varchar(50),address varchar(50),event_time int,insert_time int,code varchar(1))ENGINE=MyISAM DEFAULT CHARSET=utf8";
mysqli_query($link,$query_string);
$query_string = "insert into nucleic_acid_test_2(id,name,address,event_time,insert_time,code)values('510103199010210012','mike','shanghai',$eventTime,'1597238637','3')";
mysqli_query($link,$query_string);
$query_string ="insert into nucleic_acid_test_2(id,name,address,event_time,insert_time,code)values('510103198310607013','rose','beijing',$eventTime,'1597242237','2')";
mysqli_query($link,$query_string);
}else if($table == 'patient_90'){
$query_string = "create table patient_90(patient_id char(50),patient_name char(50),patient_gender char(1),patient_address char(50))ENGINE=MyISAM DEFAULT CHARSET=utf8";
mysqli_query($link,$query_string);
$query_string = "insert into patient_90 values('123456','王某','1','1')";
mysqli_query($link,$query_string);
}
select_table($link, $table);
}else{
echo "表已存在";
}
}
function select_table($link, $table){
$result = mysqli_query($link,"show tables like '$table'");
var_dump($result);
echo "<br>";
if ($result && mysqli_num_rows($result) > 0) {
$tableExist = true;
}else{
$tableExist = false;
}
if($tableExist){
if($table == 'user_70'){
$query_string = "select * from user_70";
$result = mysqli_query($link,$query_string);
echo "<div style='font-weight: bold;font-size: 18px;color: red; border-bottom: 1px solid #ccc;padding: 10px'>";
var_dump($result);
echo "</div><br>";
while($row = mysqli_fetch_array($result)){
echo $row['name']."<br>";
echo $row['address']."<br>";
echo $row['password']."<br>";
echo "<br>";
}
}
else if($table == 'nucleic_acid_test_2'){
$query_string = "select * from nucleic_acid_test_2";
$result = mysqli_query($link,$query_string);
echo "<div style='font-weight: bold;font-size: 18px;color: red; border-bottom: 1px solid #ccc;padding: 10px'>";
var_dump($result);
echo "</div><br>";
while($row = mysqli_fetch_array($result)){
echo $row['id']."<br>";
echo $row['name']."<br>";
echo $row['address']."<br>";
echo $row['event_time']."<br>";
echo $row['insert_time']."<br>";
echo $row['code']."<br>";
echo "<br>";
}
}
else if($table == 'patient_90'){
$query_string = "select * from patient_90";
$result = mysqli_query($link,$query_string);
echo "<div style='font-weight: bold;font-size: 18px;color: red; border-bottom: 1px solid #ccc;padding: 10px'>";
var_dump($result);
echo "</div><br>";
while($row = mysqli_fetch_array($result)){
echo $row['patient_id']."<br>";
echo $row['patient_name']."<br>";
echo $row['patient_gender']."<br>";
echo $row['patient_address']."<br>";
echo "<br>";
}
}
}
}

38
spider_251_2.php Normal file
View File

@ -0,0 +1,38 @@
<?php
// 获取传入参数
$goods = $_GET['goods'] ?? null;
// 检查参数是否提供
if ($goods === null) {
echo json_encode(["error" => "Missing required parameter: goods"]);
exit;
}
// 定义目标地址
$target_url = "http://localhost:8022/goods/flash_sale_1.php";
// 使用 cURL 抓取页面内容
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // 设置超时时间
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo json_encode(["error" => "Failed to fetch the target page"]);
curl_close($ch);
exit;
}
curl_close($ch);
// 使用正则表达式匹配指定商品的价格
// 根据提供的网页结构,价格在 <span id="商品ID">价格</span> 中
$pattern = '/<span id="' . preg_quote($goods, '/') . '">(\d+)元<\/span>/';
if (preg_match($pattern, $response, $matches)) {
// 提取并输出价格
echo json_encode([(int)$matches[1]]);
} else {
// 如果没有匹配到价格,返回提示信息
echo json_encode(["error" => "Price not found for the specified goods"]);
}
?>

46
upload_1.php Normal file
View File

@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>文件上传</title>
</head>
<body>
<?php
// 定义文件上传目录
$uploadDir = __DIR__ . "/upload/tmp/";
// 检查并创建目录
if (!file_exists($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
// 处理文件上传
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["upload_file"])) {
$file = $_FILES["upload_file"];
$fileName = basename($file["name"]);
$targetFile = $uploadDir . $fileName;
// 检查文件是否上传成功
if ($file["error"] === UPLOAD_ERR_OK) {
// 移动文件到指定目录
if (move_uploaded_file($file["tmp_name"], $targetFile)) {
echo "<p>文件上传成功!文件名:{$fileName}</p>";
echo "<p>存储路径:{$targetFile}</p>";
} else {
echo "<p>文件上传失败,请检查目录权限!</p>";
}
} else {
echo "<p>文件上传出错,错误码:" . $file["error"] . "</p>";
}
}
?>
<!-- 文件上传表单 -->
<form action="upload_1.php" method="post" enctype="multipart/form-data">
<label for="upload_file">请选择文件:</label>
<input type="file" id="upload_file" name="upload_file">
<br><br>
<input type="submit" id="ok" name="ok" value="上传">
</form>
</body>
</html>

22
user_info.php Normal file
View File

@ -0,0 +1,22 @@
<?php
session_start(); // 启用 Session
// 检查是否登录
if (!isset($_SESSION['s_name'])) {
echo "未登录!请先登录。";
header("Location: login.php"); // 跳转到登录页面
exit();
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>用户信息</title>
</head>
<body>
<h1>欢迎, <?php echo htmlspecialchars($_SESSION['s_name']); ?>!</h1>
</body>
</html>

7
www/admin/main.php Normal file
View File

@ -0,0 +1,7 @@
<?php
?>
<html>
<head>
<title>main</title>
</head>
</html>

7
www/config/config.php Normal file
View File

@ -0,0 +1,7 @@
<?php
?>
<html>
<head>
<title>config</title>
</head>
</html>

10
www/display.html Normal file
View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>display</title>
</head>
<body>
<a href="index.html">Index</a>
</body>
</html>

10
www/index.html Normal file
View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
</head>
<body>
<a href="list.html">list</a>
</body>
</html>

7
www/lib/class.php Normal file
View File

@ -0,0 +1,7 @@
<?php
?>
<html>
<head>
<title>class</title>
</head>
</html>

11
www/list.html Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>list</title>
</head>
<body>
<a href="display.html">display</a>
<a href="index.html">index</a>
</body>
</html>