Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, render_template, request, redirect, flash, url_for, session
- import mysql.connector
- from werkzeug.security import check_password_hash, generate_password_hash
- app = Flask(__name__)
- app.secret_key = "asdfghjkl12345fdsa_fdsakld8rweodfds"
- db = mysql.connector.connect(host="remotemysql.com",user="wAffmdiOi7", passwd="igBJz9WbOS", database="wAffmdiOi7")
- cur = db.cursor()
- @app.route('/')
- def home():
- return render_template('index.html')
- @app.route('/admin')
- def customertampildata():
- #cur = mysql.connection.cursor()
- cur = db.cursor()
- cur.execute("SELECT * FROM customer ORDER BY id DESC")
- datatampil = cur.fetchall()
- cur.close()
- return render_template('admin.html', datapemesan=datatampil)
- #proses insert into
- @app.route('/', methods=['POST'])
- def customerinsert():
- if request.method == 'POST':
- nama = request.form['nama']
- email = request.form['email']
- phone = request.form['phone']
- tipe = request.form['tipe']
- checkin = request.form['checkin']
- checkout = request.form['checkout']
- jml = request.form['jml']
- ket = request.form['ket']
- ##cur = mysql.connection.cursor()
- cur = db.cursor()
- cur.execute("INSERT INTO customer (nama, email, phone, tipe, checkin, checkout, jml, ket) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", (nama, email, phone, tipe, checkin, checkout, jml, ket))
- db.commit()
- flash("Data Berhasil di kirim")
- return redirect(url_for('home'))
- #proses insert into
- @app.route('/customerupdate', methods=['POST'])
- def customerupdate():
- if request.method == 'POST':
- id = request.form['id']
- nama = request.form['nama']
- email = request.form['email']
- phone = request.form['phone']
- tipe = request.form['tipe']
- checkin = request.form['checkin']
- checkout = request.form['checkout']
- jml = request.form['jml']
- status = request.form['status']
- #cur = mysql.connection.cursor()
- cur = db.cursor()
- cur.execute("UPDATE customer SET nama=%s, email=%s, phone=%s, tipe=%s, checkin=%s, checkout=%s, jml=%s, status=%s WHERE id=%s", (nama, email, phone, tipe, checkin, checkout, jml, status, id))
- db.commit()
- flash("Data Berhasil di Update")
- return redirect(url_for('customertampildata'))
- # delete data
- @app.route('/customerhapus/<int:id>', methods=["GET"])
- def customerhapus(id):
- #cur = mysql.connection.cursor()
- cur = db.cursor()
- cur.execute("DELETE FROM customer WHERE id=%s", (id,))
- db.commit()
- flash("data Berhasil di Hapus")
- return redirect( url_for('customertampildata'))
- if db.is_connected():
- print("Berhasil terhubung ke database")
- if __name__ == '__main__':
- app.run(host='0.0.0.0',debug=True, port=3306)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement