#!/usr/local/bin/python3 from cgitb import enable enable() from cgi import FieldStorage from html import escape 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, total_votes FROM candidates ORDER BY total_votes DESC, candidate_name ASC""") result = '
Candidate name | Total votes |
---|---|
%s | %i |
Sorry! We are experiencing problems at the moment. Please call back later.
' print("""