How to use PHP to develop a simple online recruitment function
With the development of the Internet, more and more companies have begun to adopt online recruitment systems to simplify the recruitment process. As a powerful and easy-to-learn development language, PHP is ideal for building online recruitment functions. This article will introduce how to use PHP to develop a simple online recruitment function and provide specific code examples for reference.
First, we need to create a database to store recruitment-related data. MySQL or other relational databases can be used. The following is the design of a simple recruitment form:
CREATE TABLE `jobs` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `description` text NOT NULL, `requirements` text, `salary` float NOT NULL, `location` varchar(255) NOT NULL, `date_posted` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Next, create a web page layout that contains the recruitment list and detailed position pages. Pages can be built using HTML and CSS. The following is an example of a simple recruitment list page:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>招聘列表</title> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>招聘列表</h1> <?php // 连接数据库 $conn = mysqli_connect("localhost", "root", "password", "database_name"); // 查询招聘信息 $query = "SELECT * FROM jobs ORDER BY date_posted DESC"; $result = mysqli_query($conn, $query); // 显示招聘列表 while ($row = mysqli_fetch_assoc($result)) { echo '<div class="job">'; echo '<h2>' . $row['title'] . '</h2>'; echo '<p>' . $row['description'] . '</p>'; echo '<p>要求:' . $row['requirements'] . '</p>'; echo '<p>薪资:' . $row['salary'] . '</p>'; echo '<p>地点:' . $row['location'] . '</p>'; echo '</div>'; } // 关闭数据库连接 mysqli_close($conn); ?> </body> </html>
In order for the company to add new recruitment information, we need to create an add recruitment information page. The following is a simple example of adding a recruitment information page:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>添加招聘信息</title> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>添加招聘信息</h1> <?php // 处理表单提交 if ($_SERVER["REQUEST_METHOD"] == "POST") { // 获取表单数据 $title = $_POST['title']; $description = $_POST['description']; $requirements = $_POST['requirements']; $salary = $_POST['salary']; $location = $_POST['location']; // 连接数据库 $conn = mysqli_connect("localhost", "root", "password", "database_name"); // 插入招聘信息 $query = "INSERT INTO jobs (title, description, requirements, salary, location, date_posted) VALUES ('$title', '$description', '$requirements', '$salary', '$location', NOW())"; mysqli_query($conn, $query); // 关闭数据库连接 mysqli_close($conn); } ?> <form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>"> <label for="title">职位标题:</label> <input type="text" id="title" name="title" required><br> <label for="description">职位描述:</label> <textarea id="description" name="description" required></textarea><br> <label for="requirements">任职要求:</label> <textarea id="requirements" name="requirements"></textarea><br> <label for="salary">薪资:</label> <input type="number" id="salary" name="salary" required><br> <label for="location">地点:</label> <input type="text" id="location" name="location" required><br> <input type="submit" value="发布招聘信息"> </form> </body> </html>
If we want to add a search function to allow users to search for recruitment information based on keywords , you can add the following code to achieve it:
<form method="get" action="search.php"> <input type="text" name="keyword" placeholder="请输入关键词"> <input type="submit" value="搜索"> </form>
Then create a search.php file to handle the search function:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>搜索结果</title> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>搜索结果</h1> <?php // 获取搜索关键词 $keyword = $_GET['keyword']; // 连接数据库 $conn = mysqli_connect("localhost", "root", "password", "database_name"); // 查询包含关键词的招聘信息 $query = "SELECT * FROM jobs WHERE title LIKE '%$keyword%' OR description LIKE '%$keyword%' OR requirements LIKE '%$keyword%'"; $result = mysqli_query($conn, $query); // 显示搜索结果 while ($row = mysqli_fetch_assoc($result)) { echo '<div class="job">'; echo '<h2>' . $row['title'] . '</h2>'; echo '<p>' . $row['description'] . '</p>'; echo '<p>要求:' . $row['requirements'] . '</p>'; echo '<p>薪资:' . $row['salary'] . '</p>'; echo '<p>地点:' . $row['location'] . '</p>'; echo '</div>'; } // 关闭数据库连接 mysqli_close($conn); ?> </body> </html>
Summary:
This article introduces how to use PHP Develop simple online recruiting functionality. By creating a database, designing web page layout, adding recruitment information, and implementing search functions, we can build a simple and practical online recruitment system. The above code examples can be used as a reference and can be modified and optimized according to specific needs. I hope this article can help you use PHP to develop online recruitment functions.
The above is the detailed content of How to use PHP to develop a simple online recruitment function. For more information, please follow other related articles on the PHP Chinese website!