Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, request
- from mysql.connector import connect
- def connect_to_db(db_name):
- cnx = connect(user="root", password="", host="localhost", database=db_name)
- cnx.autocommit = True
- return cnx
- app = Flask(__name__)
- @app.route("/")
- def main_page():
- html = """
- <html>
- <head>
- <title>Deletion</title>
- </head>
- <body>
- {}
- </body>
- </html>
- """
- try:
- cnx = connect_to_db("exercises_db")
- cur = cnx.cursor()
- my_id = request.args.get("id")
- sql = "DELETE FROM product WHERE id={};".format(my_id)
- cur.execute(sql)
- html = html.format("Usunięto produkt")
- cur.close()
- cnx.close()
- except Exception as e:
- print("An error occurred")
- print(e)
- return html
- app.run()
Add Comment
Please, Sign In to add comment