


How to use PHP to implement a simple online class adjustment and leave request system
How to use PHP to implement a simple online class adjustment and leave request system
In modern education, students often need to adjust classes or ask for leave. In order to facilitate students and teachers to manage class adjustments and leave requests, we can use PHP to implement a simple online class adjustment and leave request system. This article will introduce in detail how to use PHP to implement this system and provide specific code examples.
- Design database structure
First, we need to design the database structure to store students' course information and leave records. The following is a simple database structure design:
表名: students 字段: id, name, email, password 表名: courses 字段: id, name, room, teacher 表名: schedule 字段: id, student_id, course_id, date, time 表名: leave_requests 字段: id, student_id, course_id, date_from, date_to, reason, status
- Create database connection
Next, we need to use PHP to connect to the database. Database connections can be implemented using extensions such as mysqli or PDO. The following is a sample code that uses mysqli extension to connect to the database:
<?php $servername = "localhost"; $username = "root"; $password = "password"; $dbname = "course_system"; // 创建数据库连接 $conn = new mysqli($servername, $username, $password, $dbname); // 检查连接是否成功 if ($conn->connect_error) { die("数据库连接失败: " . $conn->connect_error); } ?>
- Implementing student login and registration functions
Students need to log in to the system to adjust classes and request leave, so We need to implement student login and registration functions. The following is a simple sample code:
<?php session_start(); if($_SERVER["REQUEST_METHOD"] == "POST") { if(isset($_POST['login'])) { $email = $_POST['email']; $password = $_POST['password']; // 查询数据库判断学生登录信息是否正确 $sql = "SELECT id, name FROM students WHERE email = '$email' AND password = '$password'"; $result = $conn->query($sql); if($result->num_rows == 1) { $row = $result->fetch_assoc(); $_SESSION['id'] = $row['id']; $_SESSION['name'] = $row['name']; header("location: dashboard.php"); } else { $error = "用户名或密码错误"; } } elseif(isset($_POST['register'])) { $name = $_POST['name']; $email = $_POST['email']; $password = $_POST['password']; // 插入学生注册信息到数据库 $sql = "INSERT INTO students (name, email, password) VALUES ('$name', '$email', '$password')"; if($conn->query($sql) === TRUE){ $success = "注册成功,请登录"; }else{ $error = "注册失败"; } } } ?> <form method="POST" action=""> <h2 id="学生登录">学生登录</h2> <input type="email" name="email" placeholder="请输入邮箱" required> <input type="password" name="password" placeholder="请输入密码" required> <button type="submit" name="login">登录</button> <h2 id="学生注册">学生注册</h2> <input type="text" name="name" placeholder="请输入姓名" required> <input type="email" name="email" placeholder="请输入邮箱" required> <input type="password" name="password" placeholder="请输入密码" required> <button type="submit" name="register">注册</button> </form>
- Implementing the function of adjusting classes and requesting leave
After students log in successfully, they can adjust classes and request leave. The following is a simple sample code:
<?php session_start(); // 检查学生是否登录 if(!isset($_SESSION['id'])) { header("location: login.php"); exit; } if($_SERVER["REQUEST_METHOD"] == "POST") { if(isset($_POST['change_course'])) { $course_id = $_POST['course_id']; $date = $_POST['date']; // 更新学生课程信息到数据库 $sql = "UPDATE schedule SET course_id = '$course_id' WHERE student_id = ".$_SESSION['id']." AND date = '$date'"; if($conn->query($sql) === TRUE){ $success = "调课成功"; }else{ $error = "调课失败"; } } elseif(isset($_POST['leave_request'])) { $course_id = $_POST['course_id']; $date_from = $_POST['date_from']; $date_to = $_POST['date_to']; $reason = $_POST['reason']; // 插入请假信息到数据库 $sql = "INSERT INTO leave_requests (student_id, course_id, date_from, date_to, reason, status) VALUES (".$_SESSION['id'].", $course_id, '$date_from', '$date_to', '$reason', 'pending')"; if($conn->query($sql) === TRUE){ $success = "请假申请已提交"; }else{ $error = "请假申请失败"; } } } ?> <form method="POST" action=""> <h2 id="调课">调课</h2> <select name="course_id"> <?php // 查询学生课程信息 $sql = "SELECT id, name FROM courses"; $result = $conn->query($sql); while($row = $result->fetch_assoc()) { echo "<option value='".$row['id']."'>".$row['name']."</option>"; } ?> </select> <input type="date" name="date" required> <button type="submit" name="change_course">确认调课</button> <h2 id="请假">请假</h2> <select name="course_id"> <?php // 查询学生课程信息 $sql = "SELECT id, name FROM courses"; $result = $conn->query($sql); while($row = $result->fetch_assoc()) { echo "<option value='".$row['id']."'>".$row['name']."</option>"; } ?> </select> <input type="date" name="date_from" required> <input type="date" name="date_to" required> <textarea name="reason" placeholder="请输入请假原因" required></textarea> <button type="submit" name="leave_request">提交请假</button> </form>
In the above code, we use Session to track whether students are logged in, and to process class transfer and leave requests. Simple page forms can be implemented using HTML.
With this simple sample code, we can implement a simple online class adjustment and leave request system. Of course, this is just a preliminary implementation and you can modify and extend it according to your specific needs. I hope this article will be helpful to implement a class adjustment and leave request system using PHP!
The above is the detailed content of How to use PHP to implement a simple online class adjustment and leave request system. For more information, please follow other related articles on the PHP Chinese website!

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.