PHP Study Notes: Human Resource Management and Recruitment System
Human resource management plays a vital role in modern enterprises. With the development of technology, many companies are turning to information technology to manage their human resources. As a popular server-side scripting language, PHP is widely used to develop various enterprise application systems, including human resources management and recruitment systems. This article will introduce how to use PHP to develop a simple human resources management and recruitment system, and provide some specific code examples.
First, we need to create a database to store employee and job applicant information. MySQL or other relational databases can be used. Here is an example of creating an employee table and an applicant table:
CREATE TABLE employees ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50) NOT NULL, email VARCHAR(50) NOT NULL, position VARCHAR(50) NOT NULL ); CREATE TABLE applicants ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50) NOT NULL, email VARCHAR(50) NOT NULL, position VARCHAR(50) NOT NULL, resume TEXT NOT NULL );
Connecting to the database using PHP is very simple. Here is an example of connecting to a MySQL database:
<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "hr_management"; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 检查连接是否成功 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } echo "连接成功"; ?>
Here is an example code to add employee and applicant records to the database :
<?php // 处理添加员工的请求 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["add_employee"])) { $name = $_POST["name"]; $email = $_POST["email"]; $position = $_POST["position"]; // 插入记录到员工表 $sql = "INSERT INTO employees (name, email, position) VALUES ('$name', '$email', '$position')"; if ($conn->query($sql) === TRUE) { echo "添加员工成功"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } } // 处理添加求职者的请求 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["add_applicant"])) { $name = $_POST["name"]; $email = $_POST["email"]; $position = $_POST["position"]; $resume = $_POST["resume"]; // 插入记录到求职者表 $sql = "INSERT INTO applicants (name, email, position, resume) VALUES ('$name', '$email', '$position', '$resume')"; if ($conn->query($sql) === TRUE) { echo "添加求职者成功"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } } ?>
The following is a sample code for a simple recruitment management page:
<!DOCTYPE html> <html> <head> <title>招聘管理</title> </head> <body> <h1>招聘管理</h1> <h2>添加员工</h2> <form method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>"> <input type="text" name="name" placeholder="姓名" required> <input type="email" name="email" placeholder="电子邮箱" required> <input type="text" name="position" placeholder="职位" required> <button type="submit" name="add_employee">添加员工</button> </form> <h2>添加求职者</h2> <form method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>"> <input type="text" name="name" placeholder="姓名" required> <input type="email" name="email" placeholder="电子邮箱" required> <input type="text" name="position" placeholder="期望职位" required> <textarea name="resume" placeholder="简历" required></textarea> <button type="submit" name="add_applicant">添加求职者</button> </form> </body> </html>
Through the above steps, we have established A simple HR management and recruitment system that adds employee and applicant records and saves them to a database. Of course, this is just a simple example, and a real human resources management system may require more functions and pages.
Summary
This article briefly introduces how to use PHP to develop a simple human resources management and recruitment system. We learned how to create a database, connect to the database, and add employee and applicant records. Of course, the actual system may require more functions, such as viewing and editing records. I hope this article will be helpful to you in the process of learning PHP.
The above is the detailed content of PHP study notes: Human resources management and recruitment system. For more information, please follow other related articles on the PHP Chinese website!