multiple submit button in python

666 views Asked by At

I am newbie to python,I have HTML form for inserting the user name and address into database using python.And have two submit type buttons ,one is add button to add the information into the database and one is delete button to delete the user information .(Python3.4)

HTML code as given below:

<!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 code :

#!"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.")

But problem is it's giving the output as "Couldn't determine which button was pressed."

It won't identify which submit button is pressed.please suggest what wrong in this code and some other solution .

0

There are 0 answers