Student information management system (PHP + MySQL)

y1409553yesi068 2021-01-21 11:20:43
student information management php mysql


One 、 effect

 

Two 、 The code framework

functions It's encapsulated in the folder mysqli Database operation function and a jump function

student Inside the folder is the main interface of the student management system

application Under the index.php It's the login interface

application Under the doAction.php The page is right application Under the index.php All kinds of responses

data Inside the folder is mysql Production database and table code

 

3、 ... and 、 Function realization

1、 The realization of mailbox verification function

By calling a third-party tool swiftmailer-master To achieve , It can be realized by simply calling the third-party tool

Get one first smtp The server ( It's used here sina, The account name and password to send the email are clivelyn@sina.com and lin123) To send mail , Send it to the mailbox registered by the user

Of course, to send an email, you have to make sure the sender , Send subject , The content of the email sent , There will be an activation link in the content of the email , Of course, this link is encrypted

Whether the account is activated or not is through the database status Keyword to determine ,status by 0 It means no activation , by 1 It means activated

The core code is as follows :

 1 // Send activation email
2 // Initialize the mail server object
3 $transport=Swift_SmtpTransport::newInstance('smtp.sina.com',25);
4 // Set user name and password
5 $transport->setUsername('clivelyn@sina.com');
6 $transport->setPassword('lin123');
7 $mailer=Swift_Mailer::newInstance($transport);// Send mail to
8 $message=Swift_Message::newInstance();// Email information objects
9 $message->setFrom(array('clivelyn@sina.com'));// Who sent
10 $message->setTo($email);// To whom?
11 $message->setSubject(' Sign up for an account to activate email ');// Set up email subject
12
13 $activeStr="?act=active&username={$username}&token={$token}";
14 $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].
15 $activeStr;
16 // echo $url;
17 // echo $url.urlencode($activeStr);
18 $urlEncode=urlencode($url);
19 //http://localhost/test/PHPAdvance/MySQLi/application/doAction.php?act=active&username=king&token=74bccca6db02607e7dd75f088ee6fee8
20 $emailBody=<<<EOF
21 welcome {$username} Use the account activation function
22 Please click the link to activate your account :
23 <a href='{$url}' target='_blank'>{$urlEncode}</a> <br />
24 ( The link is in 24 Within hours )
25 If it's not in the form of a link , Please copy the address to your browser ( for example IE) Visit the address bar of .
26 EOF;
27 $message->setBody($emailBody,"text/html",'utf-8');
28 try{
29 $res1=$mailer->send($message);
30 var_dump($res);
31 if($res && $res1){
32 mysqli_commit($link);
33 mysqli_autocommit($link, TRUE);
34 alertMes(' Registered successfully , Activate now to use ', 'index.php');
35 }else{
36 mysqli_rollback($link);
37 alertMes(' Registration failed , Re registration ','index.php');
38 }
39
40 }catch(Swift_ConnectionException $e){
41 echo '123';
42 die(' Mail server error :').$e->getMessage();
43 }
44 break;

18、 Note here 18 It's written in line encryption ,urlencode 

 

https://www.yaoruanwen.com/n/480598.html
https://www.yaoruanwen.com/n/460064.html
https://www.yaoruanwen.com/n/457889.html
http://www.zhongjinnews.com/v-1-1288142.aspx
http://www.zhongjinnews.com/v-1-1286052.aspx
https://sx.wang1314.com/topic/2020/11/14/55345/273611-1.html

2、mysqli Usage of

Use... In code mysqli It's all encapsulated in functions again , So it's very easy to use , Including connecting to the database , Additions and deletions ,mysqli The operation of the database is also more convenient

There is also a configuration file config.php Used to store the connection parameters of the used database

Core code :

 1 <?php
2 /**
3 * Connect
4 * @param string $host
5 * @param string $user
6 * @param string $password
7 * @param string $charset
8 * @param string $database
9 * @return object Connection identifier
10 */
11 function connect1($host,$user,$password,$charset,$database) {
12 $link = mysqli_connect ( $host, $user, $password ) or die ( ' Database connection failed <br/>ERROR ' . mysqli_connect_errno () . ':' . mysqli_connect_error () );
13 mysqli_set_charset ( $link, $charset );
14 mysqli_select_db ( $link, $database ) or die ( ' Failed to open the specified database <br/>ERROR ' . mysqli_errno ( $link ) . ':' . mysqli_error ( $link ) );
15 return $link;
16 }
17 /**
18 * Connect You need to pass an array
19 * @param array $config
20 * @return object
21 */
22 function connect2($config) {
23 $link = mysqli_connect ( $config ['host'], $config ['user'], $config ['password'] ) or die ( ' Database connection failed <br/>ERROR ' . mysqli_connect_errno () . ':' . mysqli_connect_error () );
24 mysqli_set_charset ( $link, $config ['charset'] );
25 mysqli_select_db ( $link, $config ['dbName'] ) or die ( ' Failed to open the specified database <br/>ERROR ' . mysqli_errno ( $link ) . ':' . mysqli_error ( $link ) );
26 return $link;
27 }
28 /**
29 * Make a connection in the form of a constant
30 * @return unknown
31 */
32 function connect3(){
33 $link = mysqli_connect ( DB_HOST, DB_USER, DB_PWD ) or die ( ' Database connection failed <br/>ERROR ' . mysqli_connect_errno () . ':' . mysqli_connect_error () );
34 mysqli_set_charset ( $link, DB_CHARSET );
35 mysqli_select_db ( $link, DB_DBNAME ) or die ( ' Failed to open the specified database <br/>ERROR ' . mysqli_errno ( $link ) . ':' . mysqli_error ( $link ) );
36 return $link;
37 }
38
39 /*
40 array(
41 'username'=>'king',
42 'password'=>'king',
43 'age'=>'12',
44 'regTime'=>'123123123'
45 );
46 INSERT user(username,password,age,regTime) VALUES('king','king','12','123123123');
47 */
48 /**
49 * The insert
50 * @param object $link
51 * @param array $data
52 * @param string $table
53 * @return boolean
54 */
55 function insert($link,$data,$table){
56 $keys = join ( ',', array_keys ( $data ) );
57 $vals = "'" . join ( "','", array_values ( $data ) ) . "'";
58 $query = "INSERT {$table}({$keys}) VALUES({$vals})";
59 $res = mysqli_query ( $link, $query );
60 if ($res) {
61 return mysqli_insert_id ( $link );
62 } else {
63 return false;
64 }
65 }
66
67 /*
68 array(
69 'username'=>'king123',
70 'password'=>'king123',
71 'age'=>'32',
72 'regTime'=>'123123123'
73 );
74 UPDATE user SET username='king123',password='king123',age='32',regTime='123123123' WHERE id=1
75 */
76 /**
77 * update operation
78 * @param object $link
79 * @param array $data
80 * @param string $table
81 * @param string $where
82 * @return boolean
83 */
84 function update($link, $data, $table, $where = null) {
85 foreach ( $data as $key => $val ) {
86 $set .= "{$key}='{$val}',";
87 }
88 $set = trim ( $set, ',' );
89 $where = $where == null ? '' : ' WHERE ' . $where;
90 $query = "UPDATE {$table} SET {$set} {$where}";
91 $res = mysqli_query ( $link, $query );
92 if ($res) {
93 return mysqli_affected_rows ( $link );
94 } else {
95 return false;
96 }
97 }
98
99 //DELETE FROM user WHERE id=
100 /**
101 * Delete operation
102 * @param object $link
103 * @param string $table
104 * @param string $where
105 * @return boolean
106 */
107 function delete($link, $table, $where = null) {
108 $where = $where ? ' WHERE ' . $where : '';
109 $query = "DELETE FROM {$table} {$where}";
110 $res = mysqli_query ( $link, $query );
111 if ($res) {
112 return mysqli_affected_rows ( $link );
113 } else {
114 return false;
115 }
116 }
117
118 /**
119 * Query the specified record
120 * @param object $link
121 * @param string $query
122 * @param string $result_type
123 * @return array|boolean
124 */
125 function fetchOne($link, $query, $result_type = MYSQLI_ASSOC) {
126 $result = mysqli_query ( $link, $query );
127 if ($result && mysqli_num_rows ( $result ) > 0) {
128 $row = mysqli_fetch_array ( $result, $result_type );
129 return $row;
130 } else {
131 return false;
132 }
133 }
134
135 /**
136 * Check all records
137 * @param object $link
138 * @param string $query
139 * @param string $result_type
140 * @return array|boolean
141 */
142 function fetchAll($link, $query, $result_type = MYSQLI_ASSOC) {
143 $result = mysqli_query ( $link, $query );
144 if ($result && mysqli_num_rows ( $result ) > 0) {
145 while ( $row = mysqli_fetch_array ( $result, $result_type ) ) {
146 $rows [] = $row;
147 }
148 return $rows;
149 } else {
150 return false;
151 }
152 }
153
154 /**
155 * Get the number of records in the table
156 * @param object $link
157 * @param string $table
158 * @return number|boolean
159 */
160 function getTotalRows($link, $table) {
161 $query = "SELECT COUNT(*) AS totalRows FROM {$table}";
162 $result = mysqli_query ( $link, $query );
163 if ($result && mysqli_num_rows ( $result ) == 1) {
164 $row = mysqli_fetch_assoc ( $result );
165 return $row ['totalRows'];
166 } else {
167 return false;
168 }
169 }
170
171 /**
172 * Get the number of records in the result set
173 * @param object $link
174 * @param string $query
175 * @return boolean
176 */
177 function getResultRows($link, $query) {
178 $result = mysqli_query ( $link, $query );
179 if ($result) {
180 return mysqli_num_rows ( $result );
181 } else {
182 return false;
183 }
184 }
185
186
187
188 /**
189 * @param object $link
190 */
191 function getServerInfo($link) {
192 return mysqli_get_server_info ( $link );
193 }
194 /**
195 * @param object $link
196 */
197 function getClientInfo($link) {
198 return mysqli_get_client_info ( $link );
199 }
200
201 /**
202 * @param object $link
203 */
204 function getHostInfo($link){
205 return mysqli_get_host_info($link);
206 }
207
208 /**
209 * @param object $link
210 */
211 function getProtoInfo($link) {
212 return mysqli_get_proto_info ( $link );
213 }

The configuration file config.php

 1 <?php
2 $config = array(
3 'host'=>'localhost',
4 'user'=>'root',
5 'password'=>'root',
6 'charset'=>'utf8',
7 'dbName'=>'51zxw'
8 );
9
10
11 define('DB_HOST','localhost');
12 define('DB_USER','root');
13 define('DB_PWD','root');
14 define('DB_CHARSET','utf8');
15 define('DB_DBNAME','51zxw');

 

3、 The data in the database is bound to web page

The data in the database is bound to web Page is first through mysqli Take out the data , And then I'm going to show the data to web Just the page

(1)、 adopt mysqli Take out the data core code :

1 $link = connect3();
2 $query = "select * from student limit {$offSet},{$pageSize}";
3 $rows = fetchAll($link, $query);

Among them connect3() It's encapsulated Links mysql Code of the database

(2)、 Show the data to web Page core code

 1 <tbody>
2 <?php foreach ($rows as $admin):?>
3 <tr>
4 <th><?php echo $admin['id']?></th>
5 <th><?php echo $admin['username']?></th>
6 <th><?php echo $admin['age']?></th>
7 <th><?php echo $admin['sex']?></th>
8 <td>
9 <span> details </span>
10 <span> modify </span>
11 <span class="delect" data_id="<?php echo $admin['id']?>"> Delete </span>
12 </td>
13 </tr>
14 <?php endforeach;?>
15 </tbody>

In fact, just one foreach Loop through every piece of data you get

 

4、 Delete response completion

The delete operation is used ajax technology , It is through js The code puts the student's id Pass to student Under the page doAction.php Response page

And then in doAction.php Response interface through mysqli To operate the database to complete the purpose of deletion

(1)、 adopt js The code puts the student's id Pass to student Under the page doAction.php Response page core code

 1 <?php foreach ($rows as $admin):?>
2 <tr>
3 <th><?php echo $admin['id']?></th>
4 <th><?php echo $admin['username']?></th>
5 <th><?php echo $admin['age']?></th>
6 <th><?php echo $admin['sex']?></th>
7 <td>
8 <span> details </span>
9 <span> modify </span>
10 <span class="delect" data_id="<?php echo $admin['id']?>"> Delete </span>
11 </td>
12 </tr>
13 <?php endforeach;?>
14 </tbody>
15 <script>
16 $(function(){
17 $(".delect").click(function(){
18 var id = $(this).attr("data_id");
19 var url = "doAction.php?id="+id;
20 $.get(url);
21 $(this).parent().parent().empty();
22 });
23 });
24 </script>

(2)、 stay doAction.php Response interface through mysqli To operate the database to complete the purpose of deletion

 1 <?php
2 header("content-type:text/html;charset=utf-8");
3 require_once '../config/config.php';
4 require_once '../functions/common.func.php';
5 require_once '../functions/mysql.func.php';
6 $link = connect3();
7 $table = "student";
8 $id = isset($_GET["id"])?$_GET["id"]:"";
9 if($id==""){
10 // Here's the student , It was supposed to be judgment action by add Of
11 $username = $_GET["username"];
12 $age = $_GET["age"];
13 $sex = $_GET["sex"];
14 $data = compact('username','age','sex');
15 $res = insert($link, $data, $table);
16 if($res){
17 alertMes(" Insert data succeeded ", "layout-index.php");
18 }else{
19 alertMes(" Insert the failure ", "layout-index.php");
20 }
21 }else{
22 delete($link, $table,"id = ".$id);
23 }

That is the first. 22 Lines of code , The first 10 Insert the code for the operation at line 20

 

5、 Add the implementation of the operation

Adding operations is done through layout-form.html Fill in the data below the page and send it to doAction Response page , And then in doAction Response page call mysqli To complete the insertion of the database

(1)、 stay layout-form.html Fill in the data below the page and send it to doAction Response page core code

 1 <div class="panel panel-default">
2 <div class="panel-heading"> New students </div>
3 <div class="panel-body">
4 <form action="doAction.php?act=add" method="get" class="form-horizontal" role="form">
5 <div class="form-group">
6 <label class="col-sm-2 control-label"> full name </label>
7 <div class="col-sm-5">
8 <input type="text" name="username" class="form-control" placeholder=" full name ">
9 </div>
10 <div class="col-sm-5">
11 <p class="form-control-static text-danger"> Name cannot be empty </p>
12 </div>
13 </div>

(2)、 stay doAction Response page call mysqli To complete the insertion of the database

 1 <?php
2 header("content-type:text/html;charset=utf-8");
3 require_once '../config/config.php';
4 require_once '../functions/common.func.php';
5 require_once '../functions/mysql.func.php';
6 $link = connect3();
7 $table = "student";
8 $id = isset($_GET["id"])?$_GET["id"]:"";
9 if($id==""){
10 // Here's the student , It was supposed to be judgment action by add Of
11 $username = $_GET["username"];
12 $age = $_GET["age"];
13 $sex = $_GET["sex"];
14 $data = compact('username','age','sex');
15 $res = insert($link, $data, $table);
16 if($res){
17 alertMes(" Insert data succeeded ", "layout-index.php");
18 }else{
19 alertMes(" Insert the failure ", "layout-index.php");
20 }
21 }else{
22 delete($link, $table,"id = ".$id);
23 }

1、 The first 10 To the first 20 A line is the code that inserts the data

2、 This is for the convenience of the graph , It was supposed to be judgment act yes add Under the circumstances , Put this code in if It's in there

 

6、 Implementation of paging operation

Paging operation is to find the total number of entries in the database , And then know how many pages , Every page of information query is through mysql Of limit Key words , Then put the data into the corresponding page

(1)、 Take data and judge the core code of paging :

 1 <?php
2 require_once '../functions/mysql.func.php';
3 require_once '../config/config.php';
4 header("content-type:text/html;charset=utf-8");
5 $link = connect3();
6 $page = $_GET['page']?$_GET['page']:1;
7 $pageSize = 5;
8 $offSet = ($page-1)*5;
9 $table = "student";
10 $totalRows = getTotalRows($link, $table);
11 $sumPage = ceil($totalRows/$pageSize);
12 $query = "select * from student limit {$offSet},{$pageSize}";
13 $rows = fetchAll($link, $query);
14 ?>

(2)、 Select the code for the page

 1 <nav>
2 <ul class="pagination pull-right">
3 <?php
4 for($i = 1;$i<=$sumPage;$i++){
5 echo "<li><a href='layout-index.php?page={$i}'>$i</a></li>";
6 }
7
8 ?>
9 </ul>
10 </nav>

 

7、 The front-end frame uses bootstrap

 

 

 

Four 、 Complete code

The full code will be placed in github above , You can download it directly

Links are as follows :

fry404006308/PHP_StudentManage: PHP_StudentManage
https://github.com/fry404006308/PHP_StudentManage

 

Reproduced in :https://www.cnblogs.com/Renyi-Fan/p/8553223.html

版权声明
本文为[y1409553yesi068]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210121111913419k.html

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云