A middle school score management system developed by php is written above
My blog hasn't been updated for a long time. I recently read the blog of MSRA Niu, Liu Weipeng (www.mindhacks.cn). I feel deeply touched and learned a lot about algorithm learning, thinking methods, career development, and so on, so after reading several of his blogs, I did two things.
Upload all my previous project code to github and continue to write my blog.
This week, I was commissioned by a middle school to use php to write a score management system. Therefore, I recorded the system development process as a summary. I would also like to share it with you, improve progress together.
Because I am still a student at school, so there must be a lot of knowledge and experience, and the content of the article will inevitably be omitted. if you are biased, I hope you can understand it more. Communication progress is the ultimate goal. thank you!
Roles and functions of the score Management System 1. administrator
1.1 import user information (including students and teachers)
1.2.1 registration examination (including the county examination, school examination, and class examination)
1.2.2 query exam information
1.3 import score
1.4 Change password
1.5 User search
2. Instructors
2.1 view the scores of all students in this class (including scores of each subject, total score, and ranking)
2.2 Change password
3. students
3.1 view all your test scores
3.2 Change password
Specific technologies
Background language: Php
Foreground language and framework: html + javascript + jquery
Deployment Server: linux + nginx
Development Process 1. database design
The database has three tables: grades (score table), users (User table), and exams (exam table)
The user ID in the users table is the foreign key of the userid in the Grades table.
The exam id in the exams table is the foreign key of examid in grades.
2. log on
Logon page
The logon interface is a nice logon interface created with jquery on the internet. it is provided below:
Http://www.veryhuo.com/down/html/55826.html
Logon logic
If the user log on successfully reads the user type (administrator, instructor, and student) of the user, the user input is filtered out to avoid SQL statements such as special characters, and read the user name, user type, user ID, and other information into $ _ session, and then direct them to different pages (admin. php, teacher. php, student. php), and re-verify the session on these pages to prevent unauthorized users from directly accessing the page. After clicking exit, the user will leave some variables in the session empty.
3. user interface
The administrator imports user information and score information using php-reader this third-party plug-in to read the uploaded excel information, here also provides this plug-in: http://code.google.com/p/php-reader/
The. xlxs file cannot be read.
The functions of other teacher and student interfaces are simple query results and no complex functions are provided.
Some specific functions are also detailed in implementation. The following figure shows the user operation interface.
4. use logic
The administrator imports the user information (including students and teachers) and the administrator registers the examination information. The system obtains the examination ID and returns it to the administrator (an ID must be assigned to each examination to differentiate the score data imported into the grades table) the administrator imports the score table (one column is the test ID obtained in step 2) to query the score of the instructor and student logon.
(For Examination Management, the reason why the administrator needs to obtain an examination ID is that I am worried that the administrator may miss the examination result when entering the examination result, in order to let the system know that the remaining score is the previous score, a test ID is required to associate them. Therefore, this seemingly redundant step for obtaining the exam ID is introduced)
Implementation of some details
1. query all student scores on the instructor page
Because I put all the student scores in the same table grades, and each record in this table is a student's exam record, therefore, you must query the scores of the exams related to the students in this instructor class and sort the scores by rank. Therefore, you must query multiple tables, it also created the longest SQL statement in history ($ exam_id is the test ID number of all students in the instructor class previously queried ):
SELECT t1.sx,t1.yw,t1.yy,t1.wl,t1.hx,t1.sw,t1.ls,t1.zz,t1.dl, (coalesce(t1.sx,0)+coalesce(t1.yw,0)+coalesce(t1.yy,0)+coalesce(wl,0) +coalesce(hx,0)+coalesce(sw,0)+coalesce(ls,0)+coalesce(dl,0)+coalesce(zz,0)) as sumscore,t2.realname FROM myphpcj.grades as t1 ,users as t2 where t1.userid=t2.id and exam_id=".$exam_id." order by sumscore desc";
It may look a little long. here we will give a general explanation that t1 is A grades table and t2 is a user table. The two tables are combined to obtain the name, student ID, score, and total score of each student in the test. The results are sorted by the total score. because some students do not participate in the test or this test does not include, therefore, the coalesce function of mysql is used to process null values. Previously, Union table queries were rarely used. after this trial, we found that many program logic can be simplified to improve program efficiency. Some foreign keys were used in this database design, which can be said to play a significant role in simplifying program exception handling. In short, I feel that I have a deeper understanding of database development.
2. avoid duplicate names when saving files
To import user scores, I first upload the file to the files directory and then read the file content import information. I want to name all the files with a datetime stamp, which involves uploading multiple file overwrites on the same day. Finally, I want to add the upload sequence 1, 2 to the files uploaded on the same day, 3 ..... . In addition, if a file is deleted in the middle, the file uploaded later fills the digit position. Therefore, the following processing is added to the upload code:
$i=1; $save_filename="files/users".date("Y-m-d[").$i."].xls"; while(file_exists("files/users".date("Y-m-d[").$i."].xls")) { $i=$i+1; $save_filename="files/users".date("Y-m-d[").$i."].xls"; } move_uploaded_file($_FILES["grade_file"]["tmp_name"], $save_filename);
The final result is as follows:
Other functions are relatively simple, so I will not elaborate on them here. In terms of security, there is no relevant experience, but only special characters are filtered in all forms to avoid SQL injection. user logon also records the number of logon failures to prevent brute force cracking. As for XSS, the website does not provide external registration, so it does not take into consideration if the website is closed.
Conclusion
I used it all the time. net web development, this time on w3school to read the two-day php Tutorial (here I would like to like this website, it is not clear that the students can Baidu, the content of the tutorial is simplified without losing the Focus !) After that, I spent three days doing this. Although the functions were relatively simple and the interface effect was average, I was satisfied. On the one hand, I added a skill, on the other hand, we also made a simple comparison between the two technologies. I personally think php and html and js are better integrated, so it is easier to front-end, in addition, the personal feeling of development efficiency is also relatively high. net is a little higher, but it is a scripting language, and the security is certainly not. net is good, basically a comprehensive function, a large system is prone to a variety of vulnerabilities. In terms of efficiency, I have never tested it, and I have no right to speak. of course, this is just a family statement. both of them are excellent languages. Otherwise, they will not become so popular. You are also welcome to exchange and discuss your ideas.
Finally, the project has open source https://code.google.com/p/phpscores/