Home > Article > Backend Development > Second-hand recycling website developed in PHP provides user complaint reporting function
The second-hand recycling website developed by PHP provides user complaint reporting function
With the rapid development of the Internet, the second-hand trading market is gradually emerging. However, this has been followed by an increase in some bad trading practices and disputes. In order to ensure the safety of user transactions and maintain a good image of the website, a second-hand recycling website should provide user complaint reporting functions. This article will introduce how to use PHP to develop a second-hand recycling website and add user complaint reporting functions to it.
First, we need to create a database to store user complaint information. Create a table named "complaints" in MySQL, which contains the following fields:
CREATE TABLE complaints ( id INT AUTO_INCREMENT PRIMARY KEY, user_id INT NOT NULL, complaint TEXT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP );
Add a complaint form on the homepage of the website for users to submit complaint information. Add the following code in HTML:
<form action="submit_complaint.php" method="post"> <textarea name="complaint" rows="5" cols="40" placeholder="请输入您的投诉内容"></textarea> <input type="submit" value="提交投诉"> </form>
When the user clicks the submit button, it will jump to the "submit_complaint.php" page to handle the complaint information submitted by the user. In the "submit_complaint.php" file, we insert the complaint information into the database through PHP code:
<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } $complaint = $_POST['complaint']; $sql = "INSERT INTO complaints (user_id, complaint) VALUES (1, '$complaint')"; if ($conn->query($sql) === TRUE) { echo "投诉提交成功"; } else { echo "投诉提交失败: " . $conn->error; } $conn->close(); ?>
After the user submits the complaint, we also need to provide an interface for the administrator to view and handle the complaint. In the HTML code of the administrator page, we add a link to view the complaint list:
<a href="complaints.php">查看投诉列表</a>
After clicking the link, it will jump to the "complaints.php" page to display the complaint list. In the "complaints.php" file, we obtain the complaint list from the database through PHP code and display it to the administrator:
<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } $sql = "SELECT * FROM complaints"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "投诉ID: " . $row["id"]. " - 用户ID: " . $row["user_id"]. " - 投诉内容: " . $row["complaint"]. "<br>"; } } else { echo "暂无投诉列表"; } $conn->close(); ?>
Through the above steps, we have successfully added the user complaint reporting function to the second-hand recycling website . Users can make complaints through the homepage of the website, and administrators can view and handle complaints through the administrator page. The implementation of this function provides users with a safe and transparent second-hand trading environment, improving the credibility of the website and user satisfaction.
Summary:
This article introduces how to use PHP to develop a second-hand recycling website and add a user complaint reporting function to it. Through the establishment of the database and the writing of relevant PHP code, we have enabled users to make complaints and administrators to view and handle complaints. This feature is crucial to maintaining a good image of the website and the security of user transactions. I hope that readers can learn how to develop a second-hand recycling website and add related functions by studying this article.
The above is the detailed content of Second-hand recycling website developed in PHP provides user complaint reporting function. For more information, please follow other related articles on the PHP Chinese website!