


How to develop a simple online complaint suggestion system using MySQL and Python
How to use MySQL and Python to develop a simple online complaint suggestion system
Introduction:
With the development of the Internet, more and more people are beginning to choose Submitting complaints and suggestions online provides enterprises and institutions with the opportunity to better understand user needs and improve services. This article will introduce how to use MySQL and Python to develop a simple online complaint suggestion system and provide corresponding code examples.
1. System requirements analysis
Before starting development, we need to clarify the system requirements. A simple online complaint and suggestion system should have the following functions:
- User registration and login
- Submission and management of complaints and suggestions
- Query and reply to complaints and suggestions
- System management function
2. Database design
Create a database named "complaint_system" in MySQL and create the following table:
-
Users table: used to store user information, including user ID, user name, password and other fields.
CREATE TABLE users ( id INT PRIMARY KEY AUTO_INCREMENT, username VARCHAR(50) NOT NULL, password VARCHAR(50) NOT NULL );
-
complaints table: used to store complaint suggestion information, including complaint ID, complaint content, submission time, processing status and other fields.
CREATE TABLE complaints ( id INT PRIMARY KEY AUTO_INCREMENT, user_id INT, content TEXT NOT NULL, submit_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, status VARCHAR(50) );
-
replies table: used to store reply information, including reply ID, reply content, reply time and other fields.
CREATE TABLE replies ( id INT PRIMARY KEY AUTO_INCREMENT, complaint_id INT, content TEXT NOT NULL, reply_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
3. Back-end development
We use Python’s Flask framework to develop the back-end interface. First, install Flask and MySQL connection libraries:
pip install flask pip install flask-mysql
Then, write a Python file named "app.py" as the entry file for the backend. Introduce the corresponding library into the file and configure the database connection:
from flask import Flask, request, jsonify from flask_mysqldb import MySQL app = Flask(__name__) app.config['MYSQL_HOST'] = 'localhost' app.config['MYSQL_USER'] = 'root' app.config['MYSQL_PASSWORD'] = 'password' app.config['MYSQL_DB'] = 'complaint_system' mysql = MySQL(app)
Next, define routing and corresponding processing functions to implement various functions of the system:
-
User registration and login:
@app.route('/register', methods=['POST']) def register(): username = request.form['username'] password = request.form['password'] cur = mysql.connection.cursor() cur.execute("INSERT INTO users (username, password) VALUES (%s, %s)", (username, password)) mysql.connection.commit() cur.close() return jsonify({'message': 'Registration success'}) @app.route('/login', methods=['POST']) def login(): username = request.form['username'] password = request.form['password'] cur = mysql.connection.cursor() cur.execute("SELECT * FROM users WHERE username = %s AND password = %s", (username, password)) user = cur.fetchone() cur.close() if user: return jsonify({'message': 'Login success'}) else: return jsonify({'message': 'Invalid username or password'})
-
Submission and management of complaints and suggestions:
@app.route('/complaints', methods=['POST']) def submit_complaint(): user_id = request.form['user_id'] content = request.form['content'] cur = mysql.connection.cursor() cur.execute("INSERT INTO complaints (user_id, content, status) VALUES (%s, %s, %s)", (user_id, content, 'Pending')) mysql.connection.commit() cur.close() return jsonify({'message': 'Complaint submitted'}) @app.route('/complaints/<complaint_id>', methods=['PUT']) def update_complaint(complaint_id): status = request.form['status'] cur = mysql.connection.cursor() cur.execute("UPDATE complaints SET status = %s WHERE id = %s", (status, complaint_id)) mysql.connection.commit() cur.close() return jsonify({'message': 'Complaint updated'})
-
Inquiries and responses to complaints and suggestions:
@app.route('/complaints', methods=['GET']) def get_complaints(): cur = mysql.connection.cursor() cur.execute("SELECT * FROM complaints") complaints = cur.fetchall() cur.close() return jsonify({'complaints': complaints}) @app.route('/complaints/<complaint_id>/reply', methods=['POST']) def reply_complaint(complaint_id): content = request.form['content'] cur = mysql.connection.cursor() cur.execute("INSERT INTO replies (complaint_id, content) VALUES (%s, %s)", (complaint_id, content)) mysql.connection.commit() cur.close() return jsonify({'message': 'Reply submitted'})
- System management functions:
(omitted, develop corresponding routing and processing functions according to actual needs)
Finally, run the Flask application:
if __name__ == '__main__': app.run()
4. Front-end development
The development of front-end interface can be carried out using front-end technologies such as HTML, CSS and JavaScript. For the sake of simplicity here, we use Bootstrap as the front-end framework and jQuery for AJAX requests and dynamic display. Here is a simple front-end example:
<!DOCTYPE html> <html> <head> <title>Complaint System</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <h1 id="Complaint-System">Complaint System</h1> <form id="register_form"> <h2 id="Register">Register</h2> <div class="form-group"> <input type="text" class="form-control" name="username" placeholder="Username"> </div> <div class="form-group"> <input type="password" class="form-control" name="password" placeholder="Password"> </div> <button type="submit" class="btn btn-primary">Register</button> </form> <form id="login_form"> <h2 id="Login">Login</h2> <div class="form-group"> <input type="text" class="form-control" name="username" placeholder="Username"> </div> <div class="form-group"> <input type="password" class="form-control" name="password" placeholder="Password"> </div> <button type="submit" class="btn btn-primary">Login</button> </form> <!-- 其他功能界面 --> </div> <script> // 注册事件 $("#register_form").submit(function(event) { event.preventDefault(); var url = "/register"; var data = $(this).serialize(); $.post(url, data, function(response) { alert(response.message); }); }); // 登录事件 $("#login_form").submit(function(event) { event.preventDefault(); var url = "/login"; var data = $(this).serialize(); $.post(url, data, function(response) { alert(response.message); }); }); // 其他事件.... </script> </body> </html>
Now you can open the HTML file in your browser to test the functionality of the system.
Conclusion:
This article introduces how to use MySQL and Python to develop a simple online complaint suggestion system. Through the design of the database and the development of the back-end interface, functions such as user registration and login, submission and management of complaints and suggestions, query and reply to complaints and suggestions, and system management are realized. The front-end uses Bootstrap and jQuery for interface development and event processing. Through this system, enterprises and institutions can better collect user feedback and improve service quality.
The above is the detailed content of How to develop a simple online complaint suggestion system using MySQL and Python. For more information, please follow other related articles on the PHP Chinese website!

The steps to create and manage user accounts in MySQL are as follows: 1. Create a user: Use CREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password'; 2. Assign permissions: Use GRANTSELECT, INSERT, UPDATEONmydatabase.TO'newuser'@'localhost'; 3. Fix permission error: Use REVOKEALLPRIVILEGESONmydatabase.FROM'newuser'@'localhost'; then reassign permissions; 4. Optimization permissions: Use SHOWGRA

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

The disadvantages of MySQL compared to other relational databases include: 1. Performance issues: You may encounter bottlenecks when processing large-scale data, and PostgreSQL performs better in complex queries and big data processing. 2. Scalability: The horizontal scaling ability is not as good as Google Spanner and Amazon Aurora. 3. Functional limitations: Not as good as PostgreSQL and Oracle in advanced functions, some functions require more custom code and maintenance.

MySQL supports four JOIN types: INNERJOIN, LEFTJOIN, RIGHTJOIN and FULLOUTERJOIN. 1.INNERJOIN is used to match rows in two tables and return results that meet the criteria. 2.LEFTJOIN returns all rows in the left table, even if the right table does not match. 3. RIGHTJOIN is opposite to LEFTJOIN and returns all rows in the right table. 4.FULLOUTERJOIN returns all rows in the two tables that meet or do not meet the conditions.

MySQL's performance under high load has its advantages and disadvantages compared with other RDBMSs. 1) MySQL performs well under high loads through the InnoDB engine and optimization strategies such as indexing, query cache and partition tables. 2) PostgreSQL provides efficient concurrent read and write through the MVCC mechanism, while Oracle and Microsoft SQLServer improve performance through their respective optimization strategies. With reasonable configuration and optimization, MySQL can perform well in high load environments.

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1
Easy-to-use and free code editor