#!/usr/bin/python2 #Fri Feb 27 10:41:05 MST 2004 #-------------MIME type statement: print "Content-type: text/html\n\n" import cgi import string import sys import os import os.path import MySQLdb #-------------Javascript redirector for input errors: redirector = 'Click here to return to login page.\n' #-------------End Javascript redirector string. #-------------Create field storage object: form = cgi.FieldStorage() #-------------Form input error handling: #IF THE SENDING FORM HAS NOT SENT THE CORRECT KEYS THEN THIS SCRIPT WILL NOT BE #PARSED BEYOND THE FOLLOWING IF STATEMENT: if not (form.has_key("firstName") and form.has_key("lastName") and form.has_key("pass")): print "\n" print "\n" print "

Error

\n" print "Please fill in your name and password.
\n" + redirector print "\n" #Footer: print "\n" sys.exit() #-------------End form input error handling. #------------- #-------------Header: print "Student Grade for %s %s\n" % (form["firstName"].value,form["lastName"].value) print "\n" print "\n" #-------------End header. print "

Student Grade for %s %s

\n" % (form["firstName"].value,form["lastName"].value) #-------------Storing input from form: first = form["firstName"].value last = form["lastName"].value password = form["pass"].value #-------------End storing input from form. #-------------Check password: #set up database connection: #Password is hard coded here. Bad design but may have time later to fix: db = MySQLdb.connect(host="localhost", user="feltc", passwd="xxxxxx", db="feltc") # CREATE A CURSOR cursor = db.cursor() # look for student and password: sql_statement = "select * from student_assignment3 where fname='" + form["firstName"].value + "' and lname='" + form["lastName"].value + "' " sql_statement = sql_statement + "and password='" + form["pass"].value + "';" #print sql_statement if not cursor.execute(sql_statement): print "

Error

\n" print "Incorrect username or password.
\n" + redirector print "\n" #Footer: print "\n" sys.exit() #-------------End Check password #-------------Script continues if username and password check out: student_results = cursor.fetchall() # GET THE RESULT SET AS A TUPLE student_values = [] for student in student_results: #print student for value in student: #print value student_values.append(value) cursor.execute("describe student_assignment3;") #Find field types. column_names = cursor.fetchall() heading_values = [] for heading in column_names: #print heading[0] heading_values.append(heading[0]) #print student_values #print heading_values print '\n' for index in range(len(student_values)): if 0 <= index <= 2: index = index#do nothing else: print "" print "" print "" index = index + 1 print "
",heading_values[index],"",student_values[index],"
" #-------------Done showing student information #Footer: print "\n"