Home >Backend Development >PHP Tutorial >How to use PHP to implement a simple online complaint and suggestion system
How to use PHP to implement a simple online complaint and suggestion system
In modern society, people have higher and higher requirements for service quality and experience. Complaints and suggestions It has become an important channel for enterprises to improve services. In order to facilitate users to send complaints and suggestions, and to manage and respond to them, we can use PHP to develop a simple online complaint and suggestion system.
System requirements analysis:
System design and implementation:
Create database and table structure:
Create a file named complaints
in the database Table, including fields id, name, contact, type, content, status, reply and created_at.
CREATE TABLE complaints ( id INT(11) AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL, contact VARCHAR(100) NOT NULL, type VARCHAR(100) NOT NULL, content TEXT NOT NULL, status ENUM('pending', 'resolved', 'replied') DEFAULT 'pending', reply TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
Front-end page design:
Create a form in the front-end page for users to submit complaints or suggestions. The form includes fields for entering your name, contact details, complaint type and details, as well as a submit button.
<form method="POST" action="submit.php"> <input type="text" name="name" placeholder="姓名" required><br> <input type="text" name="contact" placeholder="联系方式" required><br> <input type="text" name="type" placeholder="投诉类型" required><br> <textarea name="content" placeholder="具体内容" required></textarea><br> <input type="submit" value="提交"> </form>
Back-end code implementation:
a. Submit a complaint or suggestion:
Create a submit.php file, obtain the data in the form through the POST method, and insert it into the database middle.
<?php // 连接数据库 $conn = mysqli_connect("localhost", "root", "密码", "数据库名"); // 获取表单数据 $name = $_POST['name']; $contact = $_POST['contact']; $type = $_POST['type']; $content = $_POST['content']; // 插入数据到数据库 $sql = "INSERT INTO complaints (name, contact, type, content) VALUES ('$name', '$contact', '$type', '$content')"; if (mysqli_query($conn, $sql)) { echo "提交成功!"; } else { echo "提交失败:" . mysqli_error($conn); } // 关闭数据库连接 mysqli_close($conn); ?>
b. Backend management system:
Create an admin.php file for managing complaints or suggestions.
<?php // 连接数据库 $conn = mysqli_connect("localhost", "root", "密码", "数据库名"); // 查询所有投诉或建议 $sql = "SELECT * FROM complaints"; $result = mysqli_query($conn, $sql); // 输出投诉或建议列表 while ($row = mysqli_fetch_assoc($result)) { echo "姓名:" . $row['name'] . "<br>"; echo "联系方式:" . $row['contact'] . "<br>"; echo "投诉类型:" . $row['type'] . "<br>"; echo "具体内容:" . $row['content'] . "<br>"; echo "状态:" . $row['status'] . "<br>"; echo "回复:" . $row['reply'] . "<br>"; echo "提交时间:" . $row['created_at'] . "<br>"; echo "<hr>"; } // 关闭数据库连接 mysqli_close($conn); ?>
The above code example is just a simple demonstration. In actual projects, data verification, user rights control, etc. also need to be processed. Through the above steps, we can quickly use PHP to implement a simple online complaint and suggestion system, which facilitates users to submit complaints and suggestions, and can be processed and responded to in the background management system.
The above is the detailed content of How to use PHP to implement a simple online complaint and suggestion system. For more information, please follow other related articles on the PHP Chinese website!