from dbconfig import * import mysql.connector import cgi import cgitb cgitb.enable() print("Content-Type: text/html;charset=utf-8") print() print (''' ''') form = cgi.FieldStorage() patron_id = form.getfirst('patronid') if patron_id is None: print ('Please enter a valid patron id in the URL.') print ('') quit() db = get_mysql_param() cnx = mysql.connector.connect(user=db['user'], password=db['password'], host=db['host'], database=db['database']) cursor = cnx.cursor() query = ''' select p.LastName, p.FirstName, p.Phone, p.Email from Patron p where p.PatronId = %s ''' cursor.execute(query,(int(patron_id),)) row = cursor.fetchone() if row is None: print ('Sorry, no id {} in the database. Please enter a valid patron id in the URL.'. format(patron_id)) print ('') quit() (last_name, first_name, phone, email) = row print ('

Patron #{}, {} {}, {}, {}:

' .format(patron_id, last_name, first_name, phone, email)) query = ''' select e.Date, group_concat(concat(s.row, s.Number) separator ', ') as tickets from TicketSale t, Seat s, SaleItem si, performance e where e.PerformanceId = t.PerformanceId and t.SaleId = si.SaleId and si.SeatId = s.SeatId and t.PatronId = %s group by e.Date order by e.Date ''' cursor.execute(query,(int(patron_id),)) row = cursor.fetchone() if row is None: print('

No ticket purchaseed

') print ('') quit() print(''' ''') while row is not None: (date, tickets) = row print("" .format(date, tickets)) row = cursor.fetchone() cursor.close() cnx.close() print (''' ''')
DateTickets
{}{}