......_js+php综合实验学生成绩查询">
当前位置:   article > 正文

js+php+mysql实现的学生成绩管理系统_js+php综合实验学生成绩查询

js+php综合实验学生成绩查询

js+php的简单学生管理系统,自己建个students的数据库

实现的效果如下图所示:

注册

登录

系统主页

新增页面

修改页面

注册页面--register.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
  8. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  9. <style>
  10. html,body{
  11. width: 100%;
  12. height: 100%;
  13. }
  14. body{
  15. background: url(./1.png) no-repeat 100% 100%;
  16. }
  17. body .container{
  18. width: 100%;
  19. height: 100%;
  20. display: flex;
  21. justify-content: center;
  22. align-items: center;
  23. }
  24. #register{
  25. width: 400px;
  26. }
  27. .panel-footer{
  28. display: flex;
  29. /* 垂直方向 */
  30. align-items: center;
  31. /* 水平方向 */
  32. justify-content: space-between;
  33. }
  34. .alert{
  35. margin: 0px;
  36. padding: 2px;
  37. text-align: center;
  38. display: none;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <div class = 'container'>
  44. <div class = 'panel panel-primary' id = 'register'>
  45. <div class = 'panel-heading'>
  46. 注册
  47. </div>
  48. <div class = 'panel-body'>
  49. <div class = 'form-group'>
  50. <label for="username">用户名:</label>
  51. <input type="text" name = 'username' class = 'form-control' placeholder="用户名" />
  52. </div>
  53. <div class = 'form-group'>
  54. <label for="password">密码:</label>
  55. <input type="text" name = 'password' class = 'form-control' placeholder="密码" />
  56. </div>
  57. <div class = 'form-group'>
  58. <label for="repassword">确认密码:</label>
  59. <input type="text" name = 'repassword' class = 'form-control' placeholder="确认密码" />
  60. </div>
  61. <div class="alert alert-danger" role="alert">...</div>
  62. </div>
  63. <div class = 'panel-footer'>
  64. <a href="./login.html">马上登陆</a>
  65. <button class = 'btn btn-primary' id = 'registerBtn'>注册</button>
  66. </div>
  67. </div>
  68. </div>
  69. <script type = 'module'>
  70. import {$post, antiShake} from "./ajax.js";
  71. var oBtn = document.querySelector("#registerBtn");
  72. var aInputs = document.querySelectorAll(".panel-body input");
  73. var aAlert = document.querySelector(".alert");
  74. //函数防抖
  75. oBtn.onclick = antiShake(download, 1000);
  76. function download(){
  77. $post({
  78. url: "register.php",
  79. data: {
  80. username: aInputs[0].value,
  81. password: aInputs[1].value,
  82. repassword: aInputs[2].value,
  83. createTime: (new Date().getTime())
  84. },
  85. success: function(result){
  86. // console.log(result);
  87. var obj = JSON.parse(result);
  88. aAlert.style.display = 'block';
  89. if(obj.code){
  90. //错误
  91. aAlert.className = 'alert alert-danger';
  92. aAlert.innerHTML = obj.msg;
  93. }else{
  94. aAlert.className = 'alert alert-success';
  95. //成功
  96. aAlert.innerHTML = obj.msg;
  97. setTimeout(() => {
  98. location.assign("login.html");
  99. }, 500);
  100. }
  101. },
  102. error: function(msg){
  103. console.log(msg);
  104. }
  105. })
  106. }
  107. </script>
  108. </body>
  109. </html>

注册的php代码-register.php

  1. <?php
  2. header('content-type:text/html;charset="utf-8"');
  3. $responseData = array("code" => 0, "msg" => "");
  4. /*
  5. 在后台再进行一次数据校验
  6. */
  7. $username = $_POST['username'];
  8. $password = $_POST['password'];
  9. $repassword = $_POST['repassword'];
  10. $createTime = $_POST['createTime'];
  11. //1、判断用户名是否存在
  12. if(!$username){
  13. $responseData['code'] = 1;
  14. $responseData['msg'] = "用户名不能为空";
  15. echo json_encode($responseData);
  16. exit;
  17. }
  18. if(!$password){
  19. $responseData['code'] = 2;
  20. $responseData['msg'] = "密码不能为空";
  21. echo json_encode($responseData);
  22. exit;
  23. }
  24. if($password != $repassword){
  25. $responseData['code'] = 3;
  26. $responseData['msg'] = "两次输入不一致";
  27. echo json_encode($responseData);
  28. exit;
  29. }
  30. $link = mysqli_connect("127.0.0.1", "root", "123456abc");
  31. if(!$link){
  32. $responseData['code'] = 4;
  33. $responseData['msg'] = "服务器忙";
  34. echo json_encode($responseData);
  35. exit;
  36. }
  37. mysqli_set_charset($link, "utf8");
  38. mysqli_select_db($link, "qd2002");
  39. $sql = "SELECT * FROM users WHERE username='{$username}'";
  40. //mysql result
  41. $res = mysqli_query($link, $sql);
  42. //取出一行
  43. $row = mysqli_fetch_assoc($res);
  44. //已经注册
  45. if($row){
  46. $responseData['code'] = 5;
  47. $responseData['msg'] = "用户名已经存在";
  48. echo json_encode($responseData);
  49. exit;
  50. }
  51. //加密
  52. $str = md5(md5(md5($password).'qianfeng').'xiaoming');
  53. //准备sql,插入
  54. $sql2 = "INSERT INTO users (username,password,createTime) VALUES('{$username}','{$str}',{$createTime})";
  55. $res = mysqli_query($link, $sql2);
  56. if($res){
  57. $responseData['msg'] = "注册成功";
  58. echo json_encode($responseData);
  59. }else{
  60. $responseData['code'] = 6;
  61. $responseData['msg'] = "注册失败";
  62. echo json_encode($responseData);
  63. exit;
  64. }
  65. mysqli_close($link);
  66. ?>

登录页面-login.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
  8. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  9. <style>
  10. html,body{
  11. width: 100%;
  12. height: 100%;
  13. }
  14. body{
  15. background: url(./1.png) no-repeat 100% 100%;
  16. }
  17. body .container{
  18. width: 100%;
  19. height: 100%;
  20. display: flex;
  21. justify-content: center;
  22. align-items: center;
  23. }
  24. #login{
  25. width: 400px;
  26. }
  27. .panel-footer{
  28. display: flex;
  29. /* 垂直方向 */
  30. align-items: center;
  31. /* 水平方向 */
  32. justify-content: space-between;
  33. }
  34. .alert{
  35. margin: 0px;
  36. padding: 2px;
  37. text-align: center;
  38. display: none;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <div class = 'container'>
  44. <div class = 'panel panel-primary' id = 'login'>
  45. <div class = 'panel-heading'>
  46. 登陆
  47. </div>
  48. <div class = 'panel-body'>
  49. <div class = 'form-group'>
  50. <label for="username">用户名:</label>
  51. <input type="text" name = 'username' class = 'form-control' placeholder="用户名" />
  52. </div>
  53. <div class = 'form-group'>
  54. <label for="password">密码:</label>
  55. <input type="text" name = 'password' class = 'form-control' placeholder="密码" />
  56. </div>
  57. <div class="alert alert-danger" role="alert">...</div>
  58. </div>
  59. <div class = 'panel-footer'>
  60. <a href="./register.html">马上注册</a>
  61. <button class = 'btn btn-primary' id = 'loginBtn'>登陆</button>
  62. </div>
  63. </div>
  64. </div>
  65. <script type = 'module'>
  66. import {$post, antiShake} from "./ajax.js";
  67. var oBtn = document.querySelector("#loginBtn");
  68. var aInputs = document.querySelectorAll(".panel-body input");
  69. var aAlert = document.querySelector(".alert");
  70. //函数防抖
  71. oBtn.onclick = antiShake(download, 1000);
  72. function download(){
  73. $post({
  74. url: "login.php",
  75. data: {
  76. username: aInputs[0].value,
  77. password: aInputs[1].value,
  78. },
  79. success: function(result){
  80. // console.log(result);
  81. var obj = JSON.parse(result);
  82. aAlert.style.display = 'block';
  83. if(obj.code){
  84. //错误
  85. aAlert.className = 'alert alert-danger';
  86. aAlert.innerHTML = obj.msg;
  87. }else{
  88. aAlert.className = 'alert alert-success';
  89. //成功
  90. aAlert.innerHTML = obj.msg;
  91. }
  92. },
  93. error: function(msg){
  94. console.log(msg);
  95. }
  96. })
  97. }
  98. </script>
  99. </body>
  100. </html>

登录页面-login.php

  1. <?php
  2. header('content-type:text/html;charset="utf-8"');
  3. $responseData = array("code" => 0, "msg" => "");
  4. /*
  5. 在后台再进行一次数据校验
  6. */
  7. $username = $_POST['username'];
  8. $password = $_POST['password'];
  9. //1、判断用户名是否存在
  10. if(!$username){
  11. $responseData['code'] = 1;
  12. $responseData['msg'] = "用户名不能为空";
  13. echo json_encode($responseData);
  14. exit;
  15. }
  16. if(!$password){
  17. $responseData['code'] = 2;
  18. $responseData['msg'] = "密码不能为空";
  19. echo json_encode($responseData);
  20. exit;
  21. }
  22. //天龙八部
  23. //1、链接数据库
  24. $link = mysqli_connect("127.0.0.1", "root", "123456abc");
  25. //2、判断数据库是否链接成功
  26. if(!$link){
  27. $responseData['code'] = 4;
  28. $responseData['msg'] = "服务器忙";
  29. echo json_encode($responseData);
  30. exit;
  31. }
  32. //3、设置访问字符集
  33. mysqli_set_charset($link, "utf8");
  34. //4、选择我们要访问的数据库
  35. mysqli_select_db($link, "qd2002");
  36. //5、准备sql语句,进行登陆
  37. //加密
  38. $str = md5(md5(md5($password).'qianfeng').'xiaoming');
  39. $sql = "SELECT * from users WHERE username='{$username}' AND password='{$str}'";
  40. //6、发送sql语句
  41. $res = mysqli_query($link, $sql);
  42. //查询,取出其中的行
  43. $row = mysqli_fetch_assoc($res);
  44. // var_dump($row);
  45. if($row){
  46. $responseData['msg'] = "登陆成功";
  47. echo json_encode($responseData);
  48. }else{
  49. $responseData['code'] = 5;
  50. $responseData['msg'] = "用户名或密码错误";
  51. echo json_encode($responseData);
  52. exit;
  53. }
  54. mysqli_close($link);
  55. ?>

主页面 show.html

  1. < <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
  7. <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
  8. <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
  9. <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
  10. <title>Document</title>
  11. <style>
  12. .box{
  13. box-sizing: border-box;
  14. width: 100%;
  15. height: 100%;
  16. padding: 100px;
  17. position: absolute;
  18. top: 0%;
  19. left: 0%;
  20. background-color: rgba(200, 200, 200, .7);
  21. display: none;
  22. }
  23. .panel-footer{
  24. display: flex;
  25. justify-content: center;
  26. align-items: center;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div class="container">
  32. <div class="panel panel-primary">
  33. <div class="panel-heading">
  34. <h2>学生成绩管理系统</h2>
  35. </div>
  36. <div class="panel-body">
  37. <button type="button" class="btn btn-success select">获取学生成绩</button>
  38. <button type="button" class="btn btn-success add">添加学生成绩</button>
  39. <table class="table table-hover">
  40. <thead>
  41. <tr>
  42. <th>学生学号</th>
  43. <th>学生姓名</th>
  44. <th>语文成绩</th>
  45. <th>数学成绩</th>
  46. <th>英语成绩</th>
  47. <th colspan="2" style="text-align: center;">操作</th>
  48. </tr>
  49. </thead>
  50. <tbody id="tb"> </tbody>
  51. </table>
  52. </div>
  53. <div class='panel-footer'>
  54. <nav aria-label="...">
  55. <ul class="pager">
  56. <li class="previous disabled"><a href="#"><span aria-hidden="true">&larr;</span> 上一页</a></li>
  57. </ul>
  58. </nav>
  59. <nav aria-label="Page navigation">
  60. <ul class="pagination">
  61. <li class = 'active'><a href="#">1</a></li>
  62. <li><a href="#">2</a></li>
  63. <li><a href="#">3</a></li>
  64. <li><a href="#">4</a></li>
  65. <li><a href="#">5</a></li>
  66. </ul>
  67. </nav>
  68. <nav aria-label="...">
  69. <ul class="pager">
  70. <li class="next"><a href="#">下一页 <span aria-hidden="true">&rarr;</span></a></li>
  71. </ul>
  72. </nav>
  73. </div>
  74. </div>
  75. </div>
  76. <div class='panel-body box'>
  77. <div class='form-group'>
  78. <label for="username">学生姓名:</label>
  79. <input type="text" class='form-control' name='username' id="username" placeholder="学生姓名">
  80. </div>
  81. <div class='form-group'>
  82. <label for="chinese">语文成绩:</label>
  83. <input type="text" class='form-control' name='chinese' placeholder="语文成绩">
  84. </div>
  85. <div class='form-group'>
  86. <label for="math">数学成绩:</label>
  87. <input type="text" class='form-control' name='math' placeholder="数学成绩">
  88. </div>
  89. <div class='form-group'>
  90. <label for="english">英语成绩:</label>
  91. <input type="text" class='form-control' name='english' placeholder="英语成绩">
  92. </div>
  93. <button id = 'btn1' class = 'btn btn-primary cancel'>取消</button>
  94. <button id = 'submit' class = 'btn btn-primary'>确定</button>
  95. </div>
  96. </body>
  97. <script type="module">
  98. import {post} from "./ajax.js";
  99. var oBtain = document.querySelector(".select");
  100. var oAdd = document.querySelector(".add")
  101. var oTb = document.querySelector("#tb");
  102. var oBox = document.querySelector(".box");
  103. var oCancel =document.querySelector(".cancel");
  104. var oSubmit = document.getElementById("submit");
  105. //展示信息
  106. function show(){
  107. post({
  108. url:"show.php",
  109. success:function(result){
  110. var arr = JSON.parse(result);
  111. var str = '';
  112. for(var i = 0;i<arr.length;i++){
  113. str +=`<tr>
  114. <td>${arr[i].id}</td>
  115. <td>${arr[i].username}</td>
  116. <td>${arr[i].chinese}</td>
  117. <td>${arr[i].math}</td>
  118. <td>${arr[i].english}</td>
  119. <td ><button type="button" class="btn btn-danger" id='${arr[i].id}'>删除</button></td>
  120. <td><button type="button" class="btn btn-warning" id='${arr[i].id}'>修改</button></td>
  121. </tr>`
  122. }
  123. oTb.innerHTML=str;
  124. },
  125. error:function(error){
  126. console.log(error)
  127. }
  128. })
  129. }
  130. oBtain.onclick = function(){
  131. show()
  132. }
  133. var aIput = document.querySelectorAll("input");
  134. //插入信息
  135. oAdd.onclick = function(){
  136. oBox.style.display="block";
  137. oSubmit.onclick = function(){
  138. post({
  139. url:"insert.php",
  140. data:{
  141. username:aIput[0].value,
  142. chinese:aIput[1].value,
  143. math:aIput[2].value,
  144. english:aIput[3].value,
  145. },
  146. success:function(result){
  147. if(result=="success"){
  148. alert("添加成功")
  149. }else{
  150. alert("添加失败,请重试")
  151. }
  152. },
  153. error:function(error){
  154. console.log(error)
  155. }
  156. })
  157. }
  158. }
  159. oCancel.onclick = function(){
  160. oBox.style.display="none";
  161. }
  162. //删除和修改学生信息
  163. oTb.onclick = function(eve){
  164. var e = eve||window.event;
  165. var target = e.target ||e.srcElement;
  166. if(target.nodeName.toLocaleLowerCase() == 'button'){
  167. switch(target.className){
  168. //删除
  169. case 'btn btn-danger':
  170. post({
  171. url:"delete.php",
  172. data:{
  173. id:target.id
  174. },
  175. success:function(result){
  176. if(result=="success"){
  177. oTb.removeChild(target.parentNode.parentNode);
  178. alert("删除成功")
  179. }else{
  180. alert("删除失败")
  181. }
  182. }
  183. });
  184. break;
  185. //修改
  186. case 'btn btn-warning':
  187. post({
  188. url:"update.php",
  189. data:{
  190. id:target.id
  191. },
  192. success:function(result){
  193. var arr = JSON.parse(result);
  194. oBox.style.display="block";
  195. aIput[0].value=arr[0].username,
  196. aIput[1].value=arr[0].chinese,
  197. aIput[2].value=arr[0].math,
  198. aIput[3].value=arr[0].english;
  199. var id = arr[0].id;
  200. oSubmit.onclick=function(){
  201. post({
  202. url:"update1.php",
  203. data:{
  204. id:id,
  205. username:aIput[0].value,
  206. chinese:aIput[1].value,
  207. math:aIput[2].value,
  208. english:aIput[3].value,
  209. },
  210. success:function(result){
  211. if(result=="success"){
  212. alert("修改成功")
  213. }else{
  214. alert("请重新修改")
  215. }
  216. }
  217. })
  218. }
  219. }
  220. })
  221. }
  222. }
  223. }
  224. </script>
  225. </html>

show.php

  1. <?php
  2. header("content-type:text/html,charset='utf8'");
  3. $link=mysqli_connect("localhost","root","root");
  4. if(!$link){
  5. echo "服务器忙,请重试";
  6. exit;
  7. }
  8. mysqli_set_charset($link,"utf8");
  9. mysqli_select_db($link,"nz");
  10. $sql="select * from students";
  11. $res=mysqli_query($link,$sql);
  12. $arr = array();
  13. while($row=mysqli_fetch_assoc($res)){
  14. array_push($arr,$row);
  15. };
  16. echo json_encode($arr);
  17. mysqli_close($link);
  18. ?>

通过ajax传数据-ajax.js

  1. export{
  2. post,
  3. get,
  4. ajax,
  5. antiShake
  6. }
  7. //函数防抖
  8. function antiShake(func, delay){
  9. var timer = null;
  10. return function(...argus){
  11. clearTimeout(timer);
  12. if(timer == null){
  13. func.apply(this, argus);
  14. timer = "调用一次";
  15. }else{
  16. timer = setTimeout(() => {
  17. func.apply(this, argus);
  18. }, delay);
  19. }
  20. }
  21. }
  22. function post(){
  23. var argus =Object.assign({"method" :"post"},...arguments)
  24. var g = new Ajax(argus);
  25. g.init();
  26. g.type()
  27. }
  28. function get(){
  29. var argus =Object.assign({"method" :"get"},...arguments)
  30. var g = new Ajax(argus);
  31. g.init();
  32. g.type()
  33. }
  34. // function ajax(){
  35. // var a =new Ajax(...arguments);
  36. // a.init();
  37. // a.type();
  38. // }
  39. function ajax(){
  40. var a = new Ajax(...arguments);
  41. a.init();
  42. a.type()
  43. }
  44. class Ajax{
  45. constructor({method,url,data,success,error}){
  46. this.method = method;
  47. this.url = url;
  48. this.data = data;
  49. this.success = success;
  50. this.error = error;
  51. }
  52. init(){
  53. var xhr = null;
  54. try{
  55. xhr = new XMLHttpRequest;
  56. }catch{
  57. xhr = new ActiveXObject("XMLHTTP");
  58. }
  59. return xhr;
  60. }
  61. type(){
  62. var xhr= this.init()
  63. var querystring=""
  64. if(this.data){
  65. querystring = this.queryString(this.data);
  66. }
  67. if(this.method=="get"){
  68. xhr.open(this.method,this.url+"?"+querystring,true);
  69. xhr.send();
  70. }else{
  71. xhr.open(this.method,this.url,true);
  72. xhr.setRequestHeader('content-type', "application/x-www-form-urlencoded");
  73. xhr.send(querystring);
  74. }
  75. xhr.onreadystatechange = ()=>{
  76. if(xhr.readyState ==4){
  77. if(xhr.status==200){
  78. if(this.success){
  79. this.success(xhr.responseText)
  80. }
  81. }else{
  82. if(this.error){
  83. this.error("error"+xhr.status)
  84. }
  85. }
  86. }
  87. }
  88. }
  89. queryString(dataObj){
  90. var str='';
  91. for(var attr in dataObj){
  92. str+=`${attr}=${dataObj[attr]}&`
  93. }
  94. return str.substring(0,str.length-1)
  95. }
  96. }

分页-paging.php

  1. <?php
  2. header("content-type:text/html,charset='utf8'");
  3. $page = $_POST['page'] ? $_POST['page'] :1;
  4. $limit = $_POST['limit'] ? $_POST['limit']:10;
  5. $count = 0; //总条数
  6. $pages = 0; //总页数
  7. $skip = 0; //跳过的条数
  8. $link=mysqli_connect("localhost","root","root");
  9. if(!$link){
  10. echo "服务器忙,请重试";
  11. exit;
  12. }
  13. mysqli_set_charset($link,"utf8");
  14. mysqli_select_db($link,"nz");
  15. $sql = "SELECT COUNT(*) FROM students";
  16. $res=mysqli_query($link,$sql);
  17. $row = mysqli_fetch_assoc($res);
  18. $count = $row['COUNT(*)'];
  19. // echo $count;
  20. $pages = ceil($count / $limit);
  21. $page = max(1, $page);
  22. $page = min($page, $pages);
  23. $skip = ($page -1) * $limit;
  24. $msg =array(
  25. "page" => $page,
  26. "count" => $count,
  27. "pages" => $pages,
  28. "limit" => $limit,
  29. "skip" => $skip,
  30. "userlist" => array()
  31. );
  32. $sql2 = "SELECT * FROM students LIMIT {$skip}, {$limit}";
  33. $res2 = mysqli_query($link, $sql2);
  34. while($row2 = mysqli_fetch_assoc($res2)){
  35. array_push($msg['userlist'], $row2);
  36. }
  37. echo json_encode($msg);
  38. mysqli_close($link);
  39. ?>

数据添加 insert.php

  1. <?php
  2. header("content-type:text/html,charset='utf8'");
  3. $username = $_POST['username'];
  4. $chinese = $_POST['chinese'];
  5. $math = $_POST['math'];
  6. $english = $_POST['english'];
  7. $link = mysqli_connect("localhost","root","root");
  8. if(!$link){
  9. echo "服务器忙,请稍后重试";
  10. exit;
  11. };
  12. mysqli_set_charset($link,"utf8");
  13. mysqli_select_db($link,"nz");
  14. $sql ="insert into students (username,chinese,math,english) values('{$username}','{$chinese}','{$math}','{$english}')";
  15. $res = mysqli_query($link,$sql);
  16. if($res){
  17. echo "success";
  18. }else{
  19. echo "error";
  20. };
  21. mysqli_close($link);
  22. ?>

数据删除 delete.php

  1. <?php
  2. header('content-type:text/html,charset="utf8"');
  3. $id=$_POST['id'];
  4. $link=mysqli_connect("localhost","root","root");
  5. if(!$link){
  6. echo "服务器忙,请重试";
  7. exit;
  8. };
  9. mysqli_set_charset($link,"utf8");
  10. mysqli_select_db($link,"nz");
  11. $sql="delete from students where id={$id}";
  12. $res = mysqli_query($link,$sql);
  13. if($res){
  14. echo "success";
  15. }else{
  16. echo "error";
  17. };
  18. mysqli_close($link);
  19. ?>

数据修改-查找update.php

  1. <?php
  2. header("content-type:text/html,charset='utf8'");
  3. $id=$_POST['id'];
  4. $link=mysqli_connect("localhost","root","root");
  5. if(!$link){
  6. echo "服务器忙,请重试";
  7. exit;
  8. }
  9. mysqli_set_charset($link,"utf8");
  10. mysqli_select_db($link,"nz");
  11. $sql="select * from students where id ='{$id}'";
  12. $res=mysqli_query($link,$sql);
  13. $arr = array();
  14. while($row=mysqli_fetch_assoc($res)){
  15. array_push($arr,$row);
  16. };
  17. echo json_encode($arr);
  18. mysqli_close($link);
  19. ?>

数据修改-更新 update1.php

  1. <?php
  2. header("content-type:text/html,charset='utf8'");
  3. $id = $_POST['id'];
  4. $username = $_POST['username'];
  5. $chinese = $_POST['chinese'];
  6. $math = $_POST['math'];
  7. $english = $_POST['english'];
  8. $link=mysqli_connect("localhost","root","root");
  9. if(!$link){
  10. echo "服务器忙,请重试";
  11. exit;
  12. }
  13. mysqli_set_charset($link,"utf8");
  14. mysqli_select_db($link,"nz");
  15. // $sql="delete from students where id={$id}";
  16. $sql = "UPDATE students SET username ={$username} ,chinese ={$chinese},math={$math},english={$english} where id={$id}";
  17. $res=mysqli_query($link,$sql);
  18. if($res){
  19. echo "success";
  20. }else{
  21. echo "error";
  22. };
  23. mysqli_close($link);
  24. ?>
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/742616
推荐阅读
相关标签
  

闽ICP备14008679号