Home > Article > Backend Development > Source code analysis of campus lost property management system implemented in PHP
The campus lost and found management system is a practical tool that facilitates students and faculty to manage lost and found information. Through the PHP programming language, we can implement a simple and fully functional campus lost property management system. Below, I will introduce the design ideas and specific code examples of the system through source code analysis.
The lost and found management system mainly includes the following functional modules:
First we need to design the database, including the following data tables:
<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "campus_lost_found"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } ?>
<form method="post" action="submit_lost_item.php"> <input type="text" name="title" placeholder="失物名称" required> <textarea name="description" placeholder="失物描述" required></textarea> <!-- 其他字段省略 --> <button type="submit">发布失物信息</button> </form>
<?php include 'db_connect.php'; $title = $_POST['title']; $description = $_POST['description']; $user_id = $_SESSION['user_id']; $sql = "INSERT INTO lost_items (title, description, user_id) VALUES ('$title', '$description', '$user_id')"; if ($conn->query($sql) === TRUE) { echo "失物信息发布成功"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?>
<?php include 'db_connect.php'; $search_query = $_GET['search']; $sql = "SELECT * FROM lost_items WHERE title LIKE '%$search_query%' OR description LIKE '%$search_query%'"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "标题: " . $row["title"]. " - 描述: " . $row["description"]. "<br>"; } } else { echo "未找到相关失物信息"; } $conn->close(); ?>
The administrator can review, edit and delete lost property information by logging into the system backend.
<form method="post" action="admin_login.php"> <input type="text" name="username" placeholder="管理员用户名" required> <input type="password" name="password" placeholder="管理员密码" required> <button type="submit">登录</button> </form>
<?php include 'db_connect.php'; $username = $_POST['username']; $password = $_POST['password']; $sql = "SELECT * FROM users WHERE username='$username' AND password='$password' AND is_admin=1"; $result = $conn->query($sql); if ($result->num_rows > 0) { $_SESSION['admin_logged_in'] = true; echo "管理员登录成功"; } else { echo "管理员用户名或密码错误"; } $conn->close(); ?>
The above is the PHP source code analysis part in the learning example. The operation steps are relatively simple, but quite practical. I hope it will be helpful to readers when implementing similar projects.
Through this simple campus lost property management system case, you can not only deepen your understanding of the PHP language, but also exercise your programming skills. I hope readers can use this example to further improve and expand their projects and improve their programming skills.
The above is the detailed content of Source code analysis of campus lost property management system implemented in PHP. For more information, please follow other related articles on the PHP Chinese website!