I am a master student in Australia and trying to do a project - website - about accessing MySQL database in Linux platform with Python/CGI script through webpage, but the python codes didn't work.

Do you know how to do it? Can you give us some sample codes?

I have two python files as follows, can you check them what are wrong?

1)

#!/usr/bin/python
import cgi
import mysql

database = 'bestuni'
query = 'SELECT * FROM uni'

dbh = MySQL.connect('localhost', 'root', 'mypassword')
dbh.selectdb(database)

result = dbh.do(query)

print "Content-type: text/htmlrnrn"
print "<html><head><title>Python Bestuni</title></head><body>n"
for row in result:
print "Best Universities =", row[0], ", desc=", row[1], ", widgetid=", row[2], "<p>"
print "</body></html>n"

dbh.close()

2)

#!/usr/bin/python
import cgi
import pickle
import MySQL

def uni():
print "Content-type:text/htmln"
print '<html>'
print "<head><title> Harley's uni cgi</title></head>"
print '<body>'
print '<form method="POST" action="http://ip54200.scu.edu.au/harley-cgi/uni.py">'
print '<p><center><h1>The best universities around the world</h1></center></p>'
print '<p><center><h2>Do you know the best universities over the world?</h2></center></p>'
print '<p><center><input type="submit"name="yes" value="Yes"></center></p>'
print '<p><center><input type="submit"name="no" value="No"></center></p>'
print '</form>'
form=cgi.FieldStorage()
f=open("bestuni.mysql","r")
data=pickle.load(f)
f.close()
if form.has_key("new"):
print "<b>The best universities around the world are as follows:</b>"
print data[rank],data[name],data[country],data[e_mail]
elif form.has_key("no"):
print "<p>Wow, man! You don't want to those things? mmm...</p>"
f.close()
print "</body>"
print "</html>"

uni()


Pls e-mail me: goodgoodtom@yahoo.com