search
HomeDatabaseMysql TutorialHow 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

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!

Statement
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
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

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 Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools