#!/usr/local/bin/python3 from cgitb import enable enable() import pymysql as db print('Content-Type: text/html') print() result = '' try: connection = db.connect('localhost', 'userid', 'password', 'database_name') cursor = connection.cursor(db.cursors.DictCursor) cursor.execute("""SELECT candidate_name FROM candidates ORDER BY candidate_name ASC""") if cursor.rowcount == 0: result = '
Sorry. There are no candidates at present.
' else: options = '' for row in cursor.fetchall(): options += '' % (row['candidate_name'], row['candidate_name']) result = """""" % (options) cursor.close() connection.close() except db.Error: result = 'Sorry! We are experiencing problems at the moment. Please call back later.
' print("""