我是python的新手,我有使用python将用户名和地址插入数据库的HTML表单。有两个提交类型按钮,一个是添加按钮将信息添加到数据库中,一个是删除按钮删除用户信息。(Python3.4)
HTML代码如下:
<!doctype html>
<html>
<head>
<title>demo web file python3.2</title>
<link rel="stylesheet" type="text/css" href="wel.css">
</head>
<body>
<form action="/cgi-bin/python3.py" method="post">
<label>First Name: <input type="text" name="first_name"></label><br />
<label>address:<input type="text" name="pass" /></label><br />
<input type="submit" value="add" name="add" />
<input type="submit" value="delete" name="delete" />
</form>
</body>
</html>
Python代码:
#!"C:\python34\python.exe"
import cgitb ,cgi
import sys
import mysql.connector
cgitb.enable()
form = cgi.FieldStorage()
print("Content-Type: text/html;charset=utf-8")
print()
/*database connection*/
if "add" in form:
/*code to insert into database*/
elif "delete" in form:
/* code delete from database*/
else:
print ("Couldn't determine which button was pressed.")
但问题在于它输出的结果是&#34;无法确定按下了哪个按钮。&#34;
它无法识别哪个提交按钮被按下。请注意此代码和其他解决方案中的错误。