Home > Article > Backend Development > How to use PHP to develop a simple recruitment information publishing function
How to use PHP to develop a simple recruitment information publishing function
In recent years, with the rapid development of the Internet, recruitment information publishing platforms have become more and more important. As a powerful and easy-to-learn back-end development language, PHP provides us with a wealth of tools and functions to implement the recruitment information publishing function. This article will introduce how to use PHP to develop a simple recruitment information publishing function and provide specific code examples.
CREATE TABLE jobs ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, description TEXT NOT NULL, company VARCHAR(255) NOT NULL, location VARCHAR(255) NOT NULL, salary DECIMAL(10, 2) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
<form method="POST" action="submit_job.php"> <input type="text" name="title" placeholder="职位名称" required> <textarea name="description" placeholder="职位描述" required></textarea> <input type="text" name="company" placeholder="公司名称" required> <input type="text" name="location" placeholder="工作地点" required> <input type="text" name="salary" placeholder="薪资" required> <button type="submit">发布</button> </form>
<?php // 连接到数据库 $connection = mysqli_connect("localhost", "root", "password", "database_name"); // 检查是否连接成功 if (!$connection) { die("数据库连接失败:" . mysqli_connect_error()); } // 获取表单中的数据 $title = $_POST['title']; $description = $_POST['description']; $company = $_POST['company']; $location = $_POST['location']; $salary = $_POST['salary']; // 将数据插入到数据库中 $sql = "INSERT INTO jobs (title, description, company, location, salary) VALUES ('$title', '$description', '$company', '$location', $salary)"; if (mysqli_query($connection, $sq)) { echo "招聘信息发布成功!"; } else { echo "发布失败:" . mysqli_error($connection); } // 关闭数据库连接 mysqli_close($connection); ?>
<?php // 连接到数据库 $connection = mysqli_connect("localhost", "root", "password", "database_name"); // 检查是否连接成功 if (!$connection) { die("数据库连接失败:" . mysqli_connect_error()); } // 查询数据库中的所有招聘信息 $sql = "SELECT * FROM jobs"; $result = mysqli_query($connection, $sql); // 显示查询结果 if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { echo "<h2>{$row['title']}</h2>"; echo "<p>{$row['description']}</p>"; echo "<p>{$row['company']}</p>"; echo "<p>{$row['location']}</p>"; echo "<p>{$row['salary']}</p>"; echo "<hr>"; } } else { echo "暂无招聘信息"; } // 关闭数据库连接 mysqli_close($connection); ?>
Through the above steps, we have successfully developed a simple recruitment using PHP Information release function. Users can post job postings by filling out a form, and can also view posted job postings on another page. Of course, this is just a simple example, you can optimize and extend the code according to your own needs and business rules. Hope this article can be helpful to you!
The above is the detailed content of How to use PHP to develop a simple recruitment information publishing function. For more information, please follow other related articles on the PHP Chinese website!