Python 3.x 标题前的Python CGI和数据库脚本输出结束:register_insert.py

Python 3.x 标题前的Python CGI和数据库脚本输出结束:register_insert.py,python-3.x,mysql-python,mysql-error-1064,Python 3.x,Mysql Python,Mysql Error 1064,我正试图弄明白为什么我的html表单,进入pythonCGI数据库会返回一个错误。 当我提交表格时,上面写着: " 服务器遇到内部错误,无法完成您的请求 错误消息: 标题前的脚本输出结束:register_insert.py " 任何帮助和建议都将不胜感激 这是我的python代码: #! /Python/python import dbfunc, mysql.connector, cgi, cgitb cgitb.enable() # to enable browser to show

我正试图弄明白为什么我的html表单,进入pythonCGI数据库会返回一个错误。 当我提交表格时,上面写着:

" 服务器遇到内部错误,无法完成您的请求

错误消息: 标题前的脚本输出结束:register_insert.py "

任何帮助和建议都将不胜感激

这是我的python代码:

#! /Python/python

import dbfunc, mysql.connector, cgi, cgitb

cgitb.enable()  # to enable browser to show errors 
conn = dbfunc.getConnection()
cursor = ''

form = cgi.FieldStorage()               # receives all form data sent by client and saves in a dictionary (key, value pairs)

customer_info = {

customer_ID = 4
firstName = form.getvalue('firstName')  # get value of 'id' field sent by client form
lastName = form.getvalue('lastName')
addressLine1 = form.getvalue('addressLine1')
addressLine2 = form.getvalue('addressLine2')
city = form.getvalue('city')
county = form.getvalue('county')
postcode = form.getvalue('postcode')
phonenumber = form.getvalue('phonenumber')
email = form.getvalue('email')
password = form.getvalue('password')

}

print "Content-type: text/html \n"
print "<html>"
print "<head>"
print "<title> New Customer </title>"
print "</head>"
print "<body>"

if conn.is_connected():
  cursor = conn.cursor()

    new_register ("INSERT INTO registration "
                "(customer_ID, firstName, lastName, addressLine1, addressLine2, city, county, postcode, phonenumber, email, password) "
                "VALUES (%(customer_ID)d, %(firstName)s, %(lastName)s, %(addressLine1)s, %(addressLine2)s, %(city)s, %(county)s, %(postcode)s, %(phonenumber)s, %(email)s, %(password)s)")

    cursor.execute(new_register, customer_info)

    conn.commit()    
    cursor.close()
    conn.close()

else:
    print ('<H2> Error in database connection </H2>')


print "</body>"
print "</html>"
#/Python/Python
导入dbfunc、mysql.connector、cgi、cgitb
cgib.enable()#启用浏览器以显示错误
conn=dbfunc.getConnection()
游标=“”
form=cgi.FieldStorage()#接收客户端发送的所有表单数据并保存在字典中(键、值对)
客户信息={
客户识别码=4
firstName=form.getvalue('firstName')#获取客户端表单发送的'id'字段的值
lastName=form.getvalue('lastName')
addressLine1=form.getvalue('addressLine1')
addressLine2=form.getvalue('addressLine2')
city=form.getvalue('city')
county=form.getvalue('county')
postcode=form.getvalue('postcode')
phonenumber=form.getvalue('phonenumber')
email=form.getvalue('email')
password=form.getvalue('password')
}
打印“内容类型:文本/html\n”
打印“”
打印“”
打印“新客户”
打印“”
打印“”
如果连接已连接():
游标=连接游标()
新登记册(“插入登记册”
(客户ID、名、姓、地址行1、地址行2、城市、县、邮政编码、电话号码、电子邮件、密码)
“值(%(客户ID)d、%(名字)s、%(姓氏)s、%(地址行1)s、%(地址行2)s、%(城市)s、%(县)s、%(邮政编码)s、%(电话号码)s、%(电子邮件)s、%(密码)s)”)
cursor.execute(新注册、客户信息)
康涅狄格州提交
cursor.close()
康涅狄格州关闭
其他:
打印('数据库连接错误')
打印“”
打印“”
和HTML表单

<HTML>
<HEAD>
</HEAD>
<BODY>

<table width = "400" border="1" cellpadding="0">
<tr>
<td> Test Form for booking <br /> <br /> 

<form action="register_insert.py" method="post">

First Name: <input type="text" name="firstName" >  <br />

Last Name: <input type="text" name="lastName"> <br />

Address 1: <input type="text" name="addressLine1">  <br />

Address 2: <input type="text" name="addressLine2"> <br />

City: <input type="text" name="city">  <br />

County: <input type="text" name="county"> <br />

Postcode: <input type="text" name="postcode">  <br />

Phone number: <input type="text" name="phonenumber"> <br />

Email: <input type="text" name="email"> <br />

Password: <input type="text" name="password">  <br />


<input type="submit" value="Submit" />

</form>

</td>
</tr>
</table>















</BODY>
</HTML>

预订测试表

名字:
姓氏:
地址1:
地址2:
城市:
县:
邮政编码:
电话号码:
电子邮件:
密码: