Новые записи не появятся в cgi
HTML
<!doctype html> <html> <head><meta charset="utf-8"> <title>Employee Add</title></head> <body> <h1> Employee Table </h1> <form action="EmployeeAdd.cgi" method="get"> <input type="hidden" value="add" name="choice"> <p>Email: <input type="text" name="Email"><p> <p>First_Name: <input type="text" name="First Name"><p> <p>Last_Name: <input type="text" name="Last Name"><p> <p>Phone: <input type="int" name="Phone"><p> <p>Admin: <input type="text" name="Admin"><p> <p>Active: <input type="text" name="Active"><p> <input type="submit" value="Add Employee"> </form> </body> </html>
CGI_______________________________________________
#! /usr/bin/env python3 print('Content-type: text/html\n') import MySQLdb, cgi def results_table(records): html = """ <!doctype html> <html> <head><meta charset="utf-8"> <link rel="stylesheet" href="http://cgi.soic.indiana.edu/~dpierz/i211.css"> <title>Employee Add</title></head> <body> <h1>New Employee Added!</h1> <table border='1' width='100%'> <tr><th>Employee_ID</th><th>Email</th><th>FirstName</th><th>LastName</th><th>Phone</th><th>Admin</th><th>Active</th></tr> {content} </table> <p><a href="EmployeeAdd.html">Go Back</a></p> </body> </html>""" table = "" for row in records: table += "<tr>" for item in row: table += "<td align='center'>"+str(item)+"</td>" table += "</tr>" print(html.format(content = table)) form = cgi.FieldStorage() email = form.getfirst("email", "") first_name = form.getfirst("first_name", "") last_name = form.getfirst("last_name", "") phone = form.getfirst("phone", "") admin = form.getfirst("admin", "") active = form.getfirst("active", "") #establish DB connection string = "i495u20_bpmullen" #change this to yours password = "my+sql=i495u20_bpmullen" #change this to yours db_con = MySQLdb.connect(host="db.soic.indiana.edu", port = 3306, user=string, passwd=password, db=string) cursor = db_con.cursor() try: #Always surround .execute with a try! SQL = "INSERT INTO Employee (Email, First_name, Last_name, Phone, Admin, Active)" SQL += "VALUES ('" + email + "','" + first_name + "','" + last_name + "','" + phone + "','" + admin + "','" + active + "');" cursor.execute(SQL) db_con.commit() SQL = "SELECT * FROM Employee; " cursor.execute(SQL) results = cursor.fetchall() except Exception as e: #Here we handle the error print('<p>Something went wrong with the SQL!</p>') print(SQL) print("\nError:", e) else: #This runs if there was no error results_table(results)
Пример: Сотрудник Добавить[^]
Что я уже пробовал:
Не уверен, что синтаксическая ошибка в файле cgi
Попробовал проверить, нет ли ошибки в Mariadb