Table of Contents
Complaint System
Register
Login
Home Database Mysql Tutorial How to develop a simple online complaint suggestion system using MySQL and Python

How to develop a simple online complaint suggestion system using MySQL and Python

Sep 21, 2023 am 08:01 AM
mysql python Online complaint and suggestion system

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
    );
    Copy after login
  • 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)
    );
    Copy after login
  • 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
    );
    Copy after login

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
Copy after login

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)
Copy after login

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'})
    Copy after login
  • 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'})
    Copy after login
  • 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'})
    Copy after login
  • System management functions:
    (omitted, develop corresponding routing and processing functions according to actual needs)

Finally, run the Flask application:

if __name__ == '__main__':
    app.run()
Copy after login

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>
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Golang vs. Python: Concurrency and Multithreading Golang vs. Python: Concurrency and Multithreading Apr 17, 2025 am 12:20 AM

Golang is more suitable for high concurrency tasks, while Python has more advantages in flexibility. 1.Golang efficiently handles concurrency through goroutine and channel. 2. Python relies on threading and asyncio, which is affected by GIL, but provides multiple concurrency methods. The choice should be based on specific needs.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Python vs. JavaScript: The Learning Curve and Ease of Use Python vs. JavaScript: The Learning Curve and Ease of Use Apr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python: Automation, Scripting, and Task Management Python: Automation, Scripting, and Task Management Apr 16, 2025 am 12:14 AM

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.

How to run python with notepad How to run python with notepad Apr 16, 2025 pm 07:33 PM

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".

Golang vs. Python: Key Differences and Similarities Golang vs. Python: Key Differences and Similarities Apr 17, 2025 am 12:15 AM

Golang and Python each have their own advantages: Golang is suitable for high performance and concurrent programming, while Python is suitable for data science and web development. Golang is known for its concurrency model and efficient performance, while Python is known for its concise syntax and rich library ecosystem.

See all articles