Initial commit

This commit is contained in:
2025-01-07 17:55:50 +08:00
commit eab1d70061
86 changed files with 2772 additions and 0 deletions

7
20241208/acl_list.php Normal file
View File

@ -0,0 +1,7 @@
<meta charset="UTF-8">
<?php
$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")
);

View File

@ -0,0 +1,27 @@
<?php
// 数据库连接
include 'db_config.php';
// 获取请求参数
$id = $_GET['id'];
$name = $_GET['name'];
$address = $_GET['address'];
$event_time = intval($_GET['event_time']);
$code = $_GET['code'];
// 检查是否已有相同记录
$sql_check = "SELECT * FROM nucleic_acid_test_2 WHERE id = '$id' AND address = '$address' AND event_time = $event_time";
$result_check = $link->query($sql_check);
if ($result_check->num_rows > 0) {
// 如果已有记录,直接返回码值
echo $code;
} else {
// 插入新记录
$sql_insert = "INSERT INTO nucleic_acid_test_2 (id, name, address, event_time, code) VALUES ('$id', '$name', '$address', $event_time, '$code')";
if ($link->query($sql_insert) === TRUE) {
echo $code;
} else {
echo "插入失败: " . $link->error;
}
}

View File

@ -0,0 +1,50 @@
<?php
// 数据库连接
include "db_config.php";
$conn = $link;
// 获取请求参数
$id = $_GET['id'];
$name = $_GET['name'];
$address = $_GET['address'];
$event_time = intval($_GET['event_time']);
// 查询是否存在红码时空交集
$sql_red = "SELECT * FROM nucleic_acid_test_2
WHERE address = '$address' AND ABS(event_time - $event_time) < 1800 AND code = '3'";
$result_red = $conn->query($sql_red);
if ($result_red->num_rows > 0) {
// 存在红码时空交集,赋红码并入库
$sql_check = "SELECT * FROM nucleic_acid_test_2 WHERE id = '$id' AND address = '$address' AND event_time = $event_time";
$result_check = $conn->query($sql_check);
if ($result_check->num_rows == 0) {
$sql_insert = "INSERT INTO nucleic_acid_test_2 (id, name, address, event_time, code) VALUES ('$id', '$name', '$address', $event_time, '3')";
$conn->query($sql_insert);
}
echo "3";
$conn->close();
exit;
}
// 查询是否存在黄码时空交集
$sql_yellow = "SELECT * FROM nucleic_acid_test_2
WHERE (address = '$address' OR ABS(event_time - $event_time) < 1800) AND code = '2'";
$result_yellow = $conn->query($sql_yellow);
if ($result_yellow->num_rows > 0) {
// 存在黄码时空交集,赋黄码并入库
$sql_check = "SELECT * FROM nucleic_acid_test_2 WHERE id = '$id' AND address = '$address' AND event_time = $event_time";
$result_check = $conn->query($sql_check);
if ($result_check->num_rows == 0) {
$sql_insert = "INSERT INTO nucleic_acid_test_2 (id, name, address, event_time, code) VALUES ('$id', '$name', '$address', $event_time, '2')";
$conn->query($sql_insert);
}
echo "2";
$conn->close();
exit;
}
// 无风险,返回绿码
echo "1";
?>

4
20241208/db_config.php Normal file
View File

@ -0,0 +1,4 @@
<?php
$link=mysqli_connect('localhost','user_20241208_58012','JRWpcow0Ob6D4CV','exam_20241208_58012');
mysqli_query($link,'set names utf8');

28
20241208/drop_tables.php Normal file
View File

@ -0,0 +1,28 @@
<?php
include_once("db_config.php");
$conn = $link;
$sql = "DROP TABLE IF EXISTS `user_70`;";
$result = mysqli_query($conn, $sql);
if ($result) {
echo "Table users dropped successfully.";
} else {
echo "Error dropping table: " . mysqli_error($conn);
}
$sql = "DROP TABLE IF EXISTS `nucleic_acid_test_2`;";
$result = mysqli_query($conn, $sql);
if ($result) {
echo "Table users dropped successfully.";
} else {
echo "Error dropping table: " . mysqli_error($conn);
}
$sql = "DROP TABLE IF EXISTS `patient_90`;";
$result = mysqli_query($conn, $sql);
if ($result) {
echo "Table users dropped successfully.";
} else {
echo "Error dropping table: " . mysqli_error($conn);
}
mysqli_close($conn);

3
20241208/exam_config.php Normal file
View File

@ -0,0 +1,3 @@
<?php
$link=mysqli_connect('localhost','user_20241208_58011','7jT4K3plVvng0cn','exam_20241208_58011');
mysqli_query($link,'set names utf8');

72
20241208/exam_setup.php Normal file
View File

@ -0,0 +1,72 @@
<?php
include_once("db_config.php");
mysqli_set_charset($link, 'utf8');
$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);
echo mysqli_error($link);
$query_string = "insert into user_70(name,address,password)values('mike','shanghai','c4ca4238a0b923820dcc509a6f75849b')";
mysqli_query($link,$query_string);
echo mysqli_error($link);
$query_string = "insert into user_70(name,address,password)values('rose','beijing','c4ca4238a0b923820dcc509a6f75849b')";
mysqli_query($link,$query_string);
echo mysqli_error($link);
$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);
echo mysqli_error($link);
$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);
echo mysqli_error($link);
$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);
echo mysqli_error($link);
$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);
echo mysqli_error($link);
$query_string = "insert into patient_90 values('5100','张三','1','北京市西城区')";
mysqli_query($link,$query_string);
echo mysqli_error($link);
echo "user_70:";
$query_string = "select * from user_70;";
$result =mysqli_query($link,$query_string);
while($row = mysqli_fetch_array($result)){
echo $row['name']."<br>";
echo $row['address']."<br>";
echo $row['password']."<br>";
echo "<br>";
}
echo mysqli_error($link);
$query_string = "select * from nucleic_acid_test_2;";
$result = mysqli_query($link,$query_string);
echo mysqli_error($link);
echo "<br>";
echo "<br>";
echo "nucleic_acid_test_2:";
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>";
}
echo "<br>";
echo "<br>";
echo "patient_90:";
$query_string = "select * from patient_90;";
$result =mysqli_query($link,$query_string);
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>";
}
echo mysqli_error($link);

31
20241208/form_test_2.php Normal file
View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Test 2</title>
</head>
<body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// 获取表单提交数据
$name = htmlspecialchars($_POST['name']);
$password = md5($_POST['password']);
// 输出结果
echo "<p>提交后的姓名:$name</p>";
echo "<p>处理后的密码:$password</p>";
}
?>
<form action="form_test_2.php" method="post">
<label for="name">姓名:</label>
<input type="text" id="name" name="name" value=""><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>
</body>
</html>

View File

@ -0,0 +1,56 @@
<meta charset="UTF-8">
<?php
//里程碑 拿到浏览器提交的数据,数据重现(现场恢复) 无状态协议模式 stateless
//实现单选,复选,下拉框的数据重现
if(isset($_POST['ok'])){
//单选按钮与复选框在用户没有操作的情况下不会提交默认值到服务器,因此需要单独做逻辑处理
//var_dump($_POST);
//echo $_POST['name'];
$name=$_POST['name'];
if(isset($_POST['gender'])){
//echo $_POST['gender'];
$gender=$_POST['gender'];
}else{
$gender="";
}
if(isset($_POST['course'])){
//echo $_POST['course'][0];
$course=$_POST['course'];
}else{
$course=array();
//course=[]
}
$resume=$_POST['resume'];
//下拉框默认会提交数据,因此不需要像单选按钮一样做逻辑处理
$hometown=$_POST['hometown'];
//echo $_POST['hometown'];
}else{
$name="姓名不能为空";
$resume="请写出您的故事";
$gender="2";
$course=array("english");//默认选修服务器端程序设计
$hometown="chengdu";//默认选中成都
}
?>
<form action="" method="post">
姓名:<input type="text" id="name" name="name" value="<?php echo $name;?>"><br>
性别:<input type="radio" id="male" name="gender" value="1" <?php echo $gender=="1"?"checked":"";?>>男
<input type="radio" id="female" name="gender" value="2" <?php echo $gender=="2"?"checked":"";?>>女<br>
选课:<input type="checkbox" id="computer" name="course[]" value="computer" <?php echo in_array("computer",$course)?"checked":"";?>>computer
<input type="checkbox" id="math" name="course[]" value="math" <?php echo in_array("math",$course)?"checked":"";?>>math
<input type="checkbox" id="english" name="course[]" value="english" <?php echo in_array("english",$course)?"checked":"";?>>english
籍贯:<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>
<input type="submit" id="ok" name="ok" value="ok">
</form>
<script>
</script>

20
20241208/img_code_1.php Normal file
View File

@ -0,0 +1,20 @@
<?php
//GD
//phpinfo();
//登录验证码
session_start();
header("Content-type: image/png; charset=utf-8");
//创建一个图片
$image = imagecreate(120,30);
//定义背景颜色
$black = imagecolorallocate($image,255, 0, 0);//reb 000代表黑
//定义前景颜色
$white = imagecolorallocate($image,255, 255, 255);
imagefill($image, 0, 0, $black );//向图片中填充背景
$string = $_GET['img_code'];
//把文字写到图片中
imagestring( $image, 5, 6, 4, $string, $white);
//生成png格式图形
imagepng( $image );

80
20241208/list_72_1.php Normal file
View File

@ -0,0 +1,80 @@
<meta charset="UTF-8">
<?php
//数据列表 带编辑,新增与删除操作
//引入数据库配置文件
/*
* select * from student_1 limit 0,10
* select * from student_1 limit 10,10
*
*/
require_once "db_config.php";
mysqli_set_charset($link, 'utf8');
//取总记录数
$queryString="select count(name) as maxRows from user_70";
$rs=mysqli_query($link,$queryString);
$row=mysqli_fetch_assoc($rs);
$maxRows=$row['maxRows'];
$rowsOfPage = $_GET['rows_of_page'] ?? 10;
if(isset($_GET['action'])){
//翻页进入
if($_GET['action']=="top"){
$offset=0;
}
if($_GET['action']=="previous"){
$offset=$_GET['offset']-$rowsOfPage;
if($offset<0){
$offset=0;
}
}
if($_GET['action']=="next"){
$offset=$_GET['offset']+$rowsOfPage;
//处理最后一页的计算逻辑
if($offset>=$maxRows){
$offset=$_GET['offset'];
}
}
if($_GET['action']=='bottom'){
if($maxRows%$rowsOfPage==0){
//整页
$offset=$maxRows-$rowsOfPage;
}else{
//非整页
$offset=$maxRows-$maxRows%$rowsOfPage;
//20 10 20-10 25-25%10 20
}
}
}else{
//第一次进入偏移量为0
$offset=0;
}
$queryString="select * from user_70 limit $offset,$rowsOfPage";
$rs=mysqli_query($link,$queryString);
//用循环语句,从数据集中读出每一条记录
echo "<table border='1'>";
//id,name,password,gender,birthday,course,hometown,resume
echo "<tr><td colspan='10'>姓名列表</td>";
$pattern = '/(\d+)/';
while ($row=mysqli_fetch_assoc($rs)){
preg_match_all($pattern, $row['name'], $matches);
echo "<tr>";
echo "<td>".($matches[0][0]+1)."</td>";
echo "<td>".$row['name']."</td>";
}
echo "<tr><td colspan='10'>
<a href='list_72_1.php?action=top&offset=$offset&rows_of_page=$rowsOfPage'>首页</a>
|
<a href='list_72_1.php?action=previous&offset=$offset&rows_of_page=$rowsOfPage'>上一页</a>
|
<a href='list_72_1.php?action=next&offset=$offset&rows_of_page=$rowsOfPage'>下一页</a>
|
<a href='list_72_1.php?action=bottom&offset=$offset&rows_of_page=$rowsOfPage'>末页</a>
</td></tr>";
echo "</table>";

32
20241208/login.php Normal file
View File

@ -0,0 +1,32 @@
<meta charset="utf-8">
<?php
session_start();
include_once("db_config.php");
if(isset($_POST['ok'])){
$name = $_POST['name'];
$password =$_POST['password'];
$password = md5($password);
//此为教学代码有SQL注入漏洞
$queryString = "select count(name) as counter from user_70 where name = '$name' and password = '$password'";
$rs = mysqli_query($link,$queryString);
if($row = mysqli_fetch_assoc($rs)){
if($row['counter'] ==1){
//自动跳转到指定页面
$_SESSION['studentName'] = $name;
header("Location:user_info.php");
}else{
echo "登录失败,请检查用户名和密码是否正确\t";
}
}
}else{
$name = "";
}
?>
<body>
<div class="title">用户登录</div>
<form action="" method="post">
<label for="name">姓名:</label><input type="text" id="name" name="name" value="<?php echo $name;?>"><br>
<label for="password_1">密码:</label><input type="password" id="password" name="password" value=""><br>
<input type="submit" id="ok" name="ok" value="ok">
</form>
</body>

72
20241208/patient_90.php Normal file
View File

@ -0,0 +1,72 @@
<?php
require 'db_config.php';
$conn = $link;
mysqli_set_charset($link, 'utf8');
// 初始化变量
$patient_id = $patient_name = $patient_gender = $patient_address = "";
// 检查表单提交
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$patient_id = ($_POST['patient_id']);
$patient_name = ($_POST['patient_name']);
$patient_gender = ($_POST['patient_gender']);
$patient_address = ($_POST['patient_address']);
// 保存数据
try {
// 检查是否存在该患者
$query = "SELECT COUNT(*) AS count FROM patient_90 WHERE patient_id = '$patient_id'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
if ($row['count'] > 0) {
// 更新记录
$update_query = "UPDATE patient_90 SET
patient_name = '$patient_name',
patient_gender = '$patient_gender',
patient_address = '$patient_address'
WHERE patient_id = '$patient_id'";
mysqli_query($conn, $update_query);
} else {
// 插入新记录
$insert_query = "INSERT INTO patient_90
(patient_id, patient_name, patient_gender, patient_address)
VALUES
('$patient_id', '$patient_name', '$patient_gender', '$patient_address')";
mysqli_query($conn, $insert_query);
}
} catch (Exception $e) {
die("数据保存失败: " . $e->getMessage());
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>患者建档</title>
</head>
<body>
<h1>患者建档</h1>
<form action="patient_90.php" method="post">
<label for="patient_name">姓名:</label>
<input type="text" id="patient_name" name="patient_name" value=""><br>
<label for="patient_id">身份证:</label>
<input type="text" id="patient_id" name="patient_id" value=""><br>
<label>性别:</label>
<input type="radio" id="male" name="patient_gender" value="1" <?= $patient_gender === '1' ? 'checked' : '' ?>>
<label for="male">男</label>
<input type="radio" id="female" name="patient_gender" value="2" <?= $patient_gender === '2' ? 'checked' : '' ?>>
<label for="female">女</label><br>
<label for="patient_address">家庭住址:</label>
<input type="text" id="patient_address" name="patient_address" value=""><br>
<input type="submit" id="ok" name="ok" value="ok">
</form>
</body>
</html>

29
20241208/program_85.php Normal file
View File

@ -0,0 +1,29 @@
<?php
// 自定义函数实现首尾字母交换
function mySwap($string) {
// 检查字符串是否为空或长度为1
if (strlen($string) <= 1) {
return $string;
}
// 获取首字母和尾字母
$firstChar = $string[0];
$lastChar = $string[strlen($string) - 1];
// 替换首尾字母
$swappedString = $lastChar . substr($string, 1, -1) . $firstChar;
return $swappedString;
}
// 获取URL传递的字符串
if (isset($_GET['string'])) {
$string = $_GET['string'];
// 输出结果
echo mySwap($string);
} else {
echo "请通过URL传递字符串例如program_85.php?string=example";
}
?>
<?php

27
20241208/r_1.php Normal file
View File

@ -0,0 +1,27 @@
<?php
include_once("acl_list.php");
//isAllow($acl, "ceo", "销售管理系统");
$role = $_GET['role'];
//foreach($acl[$role] as $key=>$value){
// echo "<a href=''>$value</a><br>";
//}
isAllow($acl, $role,"r_1.php");
function isAllow($acl, $role, $resource){
if($role != ""){
if(isset($acl[$role])){
if(in_array($resource, $acl[$role])){
// echo "角色".$role."可以访问".$resource."<br>";
echo "欢迎光临";
}else{
// echo "角色无此权限,无法访问系统<br>";
echo "无权访问";
}
}else{
// echo "角色未定义,无权访问系统<br>";
echo "无权访问";
}
}else{
// echo "没有给定角色,无权访问系统<br>";
echo "无权访问";
}
}

27
20241208/r_2.php Normal file
View File

@ -0,0 +1,27 @@
<?php
include_once("acl_list.php");
//isAllow($acl, "ceo", "销售管理系统");
$role = $_GET['role'];
//foreach($acl[$role] as $key=>$value){
// echo "<a href=''>$value</a><br>";
//}
isAllow($acl, $role,"r_2.php");
function isAllow($acl, $role, $resource){
if($role != ""){
if(isset($acl[$role])){
if(in_array($resource, $acl[$role])){
// echo "角色".$role."可以访问".$resource."<br>";
echo "欢迎光临";
}else{
// echo "角色无此权限,无法访问系统<br>";
echo "无权访问";
}
}else{
// echo "角色未定义,无权访问系统<br>";
echo "无权访问";
}
}else{
// echo "没有给定角色,无权访问系统<br>";
echo "无权访问";
}
}

27
20241208/r_3.php Normal file
View File

@ -0,0 +1,27 @@
<?php
include_once("acl_list.php");
//isAllow($acl, "ceo", "销售管理系统");
$role = $_GET['role'];
//foreach($acl[$role] as $key=>$value){
// echo "<a href=''>$value</a><br>";
//}
isAllow($acl, $role,"r_3.php");
function isAllow($acl, $role, $resource){
if($role != ""){
if(isset($acl[$role])){
if(in_array($resource, $acl[$role])){
// echo "角色".$role."可以访问".$resource."<br>";
echo "欢迎光临";
}else{
// echo "角色无此权限,无法访问系统<br>";
echo "无权访问";
}
}else{
// echo "角色未定义,无权访问系统<br>";
echo "无权访问";
}
}else{
// echo "没有给定角色,无权访问系统<br>";
echo "无权访问";
}
}

51
20241208/register.php Normal file
View File

@ -0,0 +1,51 @@
<meta charset="utf-8">
<?php
require_once("db_config.php");
if(isset($_POST['ok'])){
$name = $_POST['name'];
$password_1 = $_POST['password'];
//服务器端数据验证
$valid = true;
if($name == ""){
echo "姓名不能为空<br>";
$valid = false;
}
//判断姓名是否重复
$queryString = "select count(name) as counter from user_70 where name = '$name'";
$rs = mysqli_query($link,$queryString);
$row = mysqli_fetch_assoc($rs);
if($row['counter'] != 0){
// echo "用户". $name."已存在,请换名<br>";
$userExist = true;
}else{
$userExist = false;
}
if($valid && !$userExist){
//对密码加密
$password_1 = md5($password_1);
//如果验证通过,把注册信息写入表中
$queryString = "insert into user_70(name,password) values('$name','$password_1') ";
mysqli_query($link,$queryString);
echo "恭喜,注册成功!";
}
if($valid && $userExist){
$password_1 = md5($password_1);
$queryString = "update user_70 set password = '$password_1' where name = '$name'";
mysqli_query($link,$queryString);
echo "密码更新成功";
}
}else{
$name = "";
}
?>
<form action="" method="post">
姓名:<input type="text" id="name" name="name" value="<?php echo $name;?>"><br>
密码:<input type="password" id="password" name="password" value=""><br>
<input type="submit" id="ok" name="ok" value="ok">
</form>
<script>
//同学们自行完成浏览器数据验证
</script>

5
20241208/robot_251.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][1]."]";

44
20241208/search_73.php Normal file
View File

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>姓名查询</title>
</head>
<body>
<form method="POST" action="search_73.php">
<label for="search_name">姓名查询:</label>
<input type="text" id="search_name" name="search_name" required>
<input type="submit" id="ok" name="ok" value="ok">
</form>
<?php
include_once 'db_config.php';
// 检查表单是否提交
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['search_name'])) {
// 获取表单输入的姓名
$searchName = $_POST['search_name'];
// 设置字符集
mysqli_set_charset($link, "utf8");
// 准备查询语句使用准备语句以防SQL注入
$query = $link->prepare("SELECT address FROM user_70 WHERE name = ?");
$query->bind_param("s", $searchName);
$query->execute();
$result = $query->get_result();
if ($result->num_rows > 0) {
// 输出查询结果
while ($row = $result->fetch_assoc()) {
echo "<p>地址: " . htmlspecialchars($row['address']) . "</p>";
}
} else {
// 在没有查询到结果时显示
echo "<p>查无此人</p>";
}
}
?>
</body>
</html>

74
20241208/search_73_1.php Normal file
View File

@ -0,0 +1,74 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>姓名与地址查询</title>
</head>
<body>
<form method="POST" action="search_73_1.php">
<label for="searchName">姓名查询:</label>
<input type="text" id="searchName" name="searchName">
<label for="searchAddress">地址查询:</label>
<input type="text" id="searchAddress" name="searchAddress">
<label for="and">AND</label>
<input type="radio" id="and" name="searchLogic" value="and" checked>
<label for="or">OR</label>
<input type="radio" id="or" name="searchLogic" value="or">
<input type="submit" id="ok" name="ok" value="ok">
</form>
<?php
include_once 'db_config.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// 获取用户输入的查询条件
$searchName = $_POST['searchName'] ?? '';
$searchAddress = $_POST['searchAddress'] ?? '';
$searchLogic = $_POST['searchLogic'] ?? 'and';
// 设置字符集
mysqli_set_charset($link, "utf8");
// 动态构建查询语句
$conditions = [];
$params = [];
$types = '';
if (!empty($searchName)) {
$conditions[] = "name = ?";
$params[] = $searchName;
$types .= 's';
}
if (!empty($searchAddress)) {
$conditions[] = "address = ?";
$params[] = $searchAddress;
$types .= 's';
}
if (count($conditions) > 0) {
$sql = "SELECT * FROM user_70 WHERE " . implode(" " . strtoupper($searchLogic) . " ", $conditions);
$stmt = $link->prepare($sql);
$stmt->bind_param($types, ...$params);
$stmt->execute();
$result = $stmt->get_result();
$rowCount = $result->num_rows;
echo "<p>[" . $rowCount . "]</p>"; // 显示记录数
if ($rowCount > 0) {
while ($row = $result->fetch_assoc()) {
echo "<p>姓名: " . htmlspecialchars($row['name']) . " 地址: " . htmlspecialchars($row['address']) . "</p>";
}
}
$stmt->close();
} else {
// 如果没有提供查询条件则不执行查询
echo "<p>[0]</p>";
}
}
?>

3
20241208/user_info.php Normal file
View File

@ -0,0 +1,3 @@
<?php
session_start();
echo $_SESSION['studentName'];

View File

@ -0,0 +1,14 @@
<?php
?>
<!DOCTYPE html>
<html lang="Zh-CN">
<head>
<title>main</title>
</head>
<body>
<iframe src="top.html"></iframe>
<iframe src="left.html"></iframe>
<iframe src="right.html"></iframe>
</body>
</html>

View File

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

View File

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

View File

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

10
20241208/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="list.html">list.html</a>
</body>
</html>

10
20241208/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.html</a>
</body>
</html>

11
20241208/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="index.html">index.html</a>
<a href="display.html">display.html</a>
</body>
</html>