这个自己的小项目要先告一段落了。可能还有许多bug。请见谅
php:
// 这里是通过前端代码html中的 url 传过来的,用 $_get 来获取(相关html代码可以看一下到主页看一下前几条博客)
if (empty($_get['num'])) exit('<h1>找不到您要删除的学生的学号</h1>');$num = $_get['num'];$connection = mysqli_connect('localhost', 'root', '密码', 'students_info_system');if (!$connection) exit('<h1>连接数据库失败</h1>');$query = mysqli_query($connection, "delete from students where num = {$num}");if (!$query) exit('<h1>该学生信息查询失败</h1>');// 注意:这里传入的是连接对象$affected_rows = mysqli_affected_rows($connection);if ($affected_rows !== 1) exit('<h1>删除失败</h1>');header('location: student_info.php');
html:
<!doctype html><html><head> <meta chart="utf-8"> <title>编辑学生</title> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"></head><body> <div class="container mt-3"> <h1 class="display-5 text-center">编辑学生</h1> <?php if (ist($error_msg)): ?> <div class="alert alert-danger"><?php echo $error_msg; ?></div> <?php endif ?> <div class="row mt-3"> <img src="<?php echo $current_student['photo']; ?>" alt="<?php echo $current_student['name']; ?>" width="100" height="488" class="col-sm-6"> <form action="<?php echo $_rver['php_lf']; ?>?id=<?php echo $current_num; ?>" method="post" enctype="multipart/form-data" autocomplete="off" class="col-sm-6"> <div class="form-group"> <input type="number" name="num" class="form-control" placeholder="学号" value="<?php echo ist($_post['num']) ? $_post['num'] : $current_student['num']; ?>"> </div> <div class="form-group"> <lect class="form-control" name="system"> <option>请选择学院/系</option> <option <?php echo $current_student['system'] ==现在进行时的构成= '电气工程学院' ? 'lected' : ''; ?>>电气工程学院</option> <option <?php echo $current_student['system'] === '信息工程与艺术学院' ? 'lected' : ''; ?>>信息工程与艺术学院</option> <option <?php echo $current_student['system'] === '国际教育学院' ? 'lected' : ''; ?>>国际教育学院</option> <option <?php echo $current_student['system'] === '水利水电工程学院' ? 'lected' : ''; ?>>水利水电工程学院</option> <option <?php echo $current_student['system'] === '测绘与市政工程学院' ? 'lected' : ''; ?>>测绘与市政工程学院</option> <option <?php echo $current_student['system'] === '马克思主义学院' ? 'lected' : ''; ?>>马克思主义学院</option> <option <?php echo $current_student['system'] === '建筑工程学院' ? 'lected' : ''; ?>>建筑工程学院</option> <option <?php echo $current_student['system'] === '经济与管理学院' ? 'lected' : ''; ?>>经济与管理学院</option> </lect> </div> <div class="form-group"> <input type="text" name="class" class="form-control" placeholder="班级" value="<?php echo ist($_post['class']) ? $_post['class'] : $current_student['class']; ?>"> </div> <div class="form-group"> <input type="text" name="name" class="form-control" placeholder="姓名" value="<?php echo ist($_post['name']) ? $_post['name'] : $current_student['name']; ?>"> </div> <div class="form-group"> <lect class="form-control" name="gender"> <option value="-1">请选择性别</option> <option <?php echo $current_student['gender'] === '1' ? 'lected' : ''; ?> value="1">男</option> <option <?php echo $current_student['gender'] === '0' ? 'lected' : ''; ?> value="0">女</option> </lect> </div> <div class="form-group"> <label for="birthday">出生日期</label> <input type="date" name="birthday" class="form-control" id="birthday" value="<?php echo ist($_post['birthday']) ? $_post['birthday'] : $current_student['birthday']; ?>"> </div> <div class="form-group"> <label for="photo">照片</label> <input type拟人句大全="file" name="photo" class="form-control"> </div> <button type="submit" class="btn btn-info btn-block">确认修改</button> </form> </div>爱蒙幼儿园视频全集; </div></body></html>
php:
if (empty($_get['id'])) exit('<h1>必须指定相应的学号</h1>');$current_num = $_get['id'];$connection = mysqli_connect('localhost', 'root', '密码', 'students_info_system');if (!$connection) exit('<h1>连接数据库失败</h1>');$query = mysqli_query($connection, "lect * from students where num = {$current_num} limit 1");if (!$query) exit('<h1>找不到您要编辑的学生信息</h1>');$伤仲永译文current_student = mysqli_fetch_assoc($query);// var_dump($current_student);function edit_student() { // var_dump('进来了'); global $connection; global $current_num; // 当前学生学号 global $current_student; $extra_students_query = mysqli_query($connection, "lect * from students where num != {$current_num}"); if (!$extra_students_query) { exit('<h1>其余学生数据查询失败</h1>'); // return; } // 查询除该学生以外的其他学生 while ($student = mysqli_fetch_assoc($extra_students_query)) { // var_dump($student); $students_num[] = $student['num']; } // var_dump($students_num); // var_dump($_files['photo']); // var_dump($_post['gender']); if (empty($_post['num'])) { $globals['error_msg'] = '请输入学号'; return; } // 判断该学号是否已经被添加(即列表中已存在该学生)========= if (in_array($_post['num'], $students_num)) { $globals['error_msg'] = '该学生已存在'; return; } if (empty($_post['system']) || $_post['system'] === '请选择学院/系') { $globals['error_msg'] = '请选择学院/系'; return; } if (empty($_post['class'])) { $globals['error_msg'] = '请输入班级'; return; } if (empty($_post['name'])) { $globals['error_msg'] = '请输入姓名'; return; } if (!(ist($_post['gender']) && $_post['gender'] !== '-1')) { $globals['error_msg'] = '请选择性别'; return; } if (empty($_post['birthday'])) { $globals['error_msg'] = '请输入出生日期'; return; } // 以下处理文件域======================================================= // 当有文件上传时才验证,没有上传则照片不变 // $_files['photo'] = $current_student['photo']; // var_dump($_files['photo']); if ($_files['photo']['name'] !== '') { // var_dump($_files['photo']); // var_dump($_files['photo']); if ($_files['photo']['error'] !== upload_err_ok) { $globals['error_msg'] = '上传照片失败'; return; } // 验证上传文件的类型(只允许图片) if (strpos($_files['photo']['type'], 'image/') !== 0) { $globals['error_msg'] = '这不是支持的文件格式类型,请重新上传'; return; } // 文件上传到了服务端开辟的一个临时地址,需要转移到本地 $image_target = 'images/' . $_files['photo']['name']; if (!move_uploaded_file($_files['photo']['tmp_name'], $image_target)) { $globals['error_msg'] = '图片上传失败'; return; } // 接收更新过的学生照片 $current_student['photo'] = (string)$image_target; } el { // var_dump($_files['photo']); // 如果照片没有上传则不进行验证文件域,直接更新数据且不改变原来的照片 $current_student['num'] = $_post['num']; $current_student['system'] = $_post['system']; $current_student['class'] = $_post['class']; $current_student['name'] = $_post['name']; $current_student['gender'] = $_post['gender']; $current_student['birthday'] = $_post['birthday']; } // var_dump($current_num); // 将数据修改存放到数据库 $update_query = mysqli_query($connection, "update students t `num` = '{$current_student['num']}', `system` = '{$current_student['system']}', `class` = '{$current_student['class']}', `name` = '{$current_student['name']}', `gender` = '{$current_student['gender']}', `birthday` = '{$current_student['birthday']}', `photo` = '{$current_student['photo']}' where `num` = {$current_num}"); if (!$update_query) { $globals['error_msg'] = '更新数据查询失败'; return; } $affected_rows = mysqli_affected_rows($connection); if ($affected_rows !== 1) { $globals['error_msg'] = '修改失败'; return; } // 延迟2秒 time_sleep_until(time() + 2); header('location: student_info.php');}if ($_rver['request_method'] === 'post') { edit_student();}
// 关键词搜索功能----立即函数(function (element, arch_key) { let table = document.getelementbyid('table-content'); // 获取表格 function in_array_item (item, array) { for (var i = 0; i < array.length; i++) { if (array[i].indexof(item) != -1) { return true; } } return fal; } function respon () { let hiddenstudentsnumber = 0; // 获取隐藏的学生个数(即表格隐藏行数) // 获取要搜索的关键词 const arch_content = document.getelementbyid(arch_key).value; // console.log(arch_content); // console.log(typeof(arch_content)); let data = []; // 遍历列表将数据存储到一个数组中 // 1.获取表格行数 for (let i = 0; i < table.children.length; i++) { // 2.获取表格列数 for (let j = 0; j < table.children[i].children.length; j++) { if (!data[i]) { // 在数组中创键每一行内容存放的数组,用于存放一行数据 data[i] = new array(); } data[i][j] = table.children[i].children[j].innerhtml.tostring(); // 3.存放数据 if (data[i][j] === '') { data[i][j] = '男'; } if (data[i][j] === '') { data[i][j] = '女'; } } // console.log(data[i]); if (arch_content == '') { table.children[i].style.display = ''; } el { if (in_array_item(arch_content, data[i])) { table.children[i].style.display = ''; } el { table.children[i].style.display = 'none'; hiddenstudentsnumber += 1; } } } console.log(hiddenstudentsnumber); let str = "共有" + (table.children.length - hiddenstudentsnumber) + "名学生"; document.getelementbyid('students_number').innerhtml = str; } const archbutton = document.getelementbyid(element); archbutton.addeventlistener('click', function () { respon(); }); document.addeventlistener('keydown', function (event) { if (event.keycode === 13) { respon(); } }); let str = "共有" + table.children.length + "名学生"; document.getelementbyid('students_number').innerhtml = str;})('arch', 'arch-key');
同时在原有的学生信息页面html添加:
<div class="row mt-3"> <a class="btn btn-info col-sm-2" style="margin-right: 28px; margin-left: 15px;" href="add_student.php">添加学生</a>
// 添加的 <button class="btn btn-info align-middle" id="students_number"></button>
<input type="text" class="form-control col-sm-6 ml-2" autocomplete="on" placeholder="请输入关键词" value="" id="arch-key"> <button type="submit" clas氧化钠和水反应s="btn btn-info col-sm-2 ml-2" id="arch">点击搜索</button> </div>
本文发布于:2023-04-06 08:56:35,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/a2b76eb31ea2276a7bf68395d7d43766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:PHP 结合 Boostrap 结合 js 实现学生列表删除编辑以及搜索功能(完结).doc
本文 PDF 下载地址:PHP 结合 Boostrap 结合 js 实现学生列表删除编辑以及搜索功能(完结).pdf
留言与评论(共有 0 条评论) |