我的代码在服务器上运行时显示一些错误。我检查了服务器错误日志,但仍然不知道它的确切含义。它说脚本过早结束。现在我想调试我的代码来检查每一行代码它的作用是什么?我应该如何调试我的代码。我对此真的很陌生。
#!/usr/bin/python
import cgitb
import MySQLdb
import cgi
cgitb.enable()
form = cgi.FieldStorage()
f_name = form.getvalue('firstname', '')
l_name = form.getvalue('lastname', '')
age = form.getvalue('age', 0)
gender = form.getvalue('gender', '')
db = MySQLdb.connect("localhost", "root", "gaurav", "Info")
cursor = db.cursor()
sql = "INSERT INTO PERSON (F_Name, L_Name, Age, Gender) VALUES ('%s',' %s',' %d',' %s')" % (f_name, l_name, age, gender)
try:
cursor.execute(sql)
#print "Hello !!"
#print "no of rows inserted: %d " % cursor.rowcount
db.commit()
except:
db.rollback()
db.close()
print "Content-type:text/html"
print "<html>"
print "<h1>DATABASE</h1>"
print "</html>"