am building up an application form using flask where the name enter into input field has to getinto the table in mysql table . for which I've have used myphp admin through xammp. when application is everything is okay but once name is entered into input add clicked on ADD am getting the following error.
TypeError: 'str' object cannot be interpreted as an integer
below is my python code .
from flask import Flask, render_template, request
from flask_mysqldb import MySQL
import mysql.connector
tenant_app = Flask(__name__)
# mysql db configuaration
tenant_app.config['MYSQL_HOST'] = ''
tenant_app.config['MYSQL_DB'] = ''
tenant_app.config['MYSQL_USER'] = ''
tenant_app.config['MYSQL_PASSWORD'] = ''
tenant_app.config['MYSQL_PORT'] = ''
mysql = MySQL(tenant_app)
@tenant_app.route('/', methods=['GET', 'POST'])
def felty_tenant():
if request.method == "POST":
details = request.form
Tenant = details["tenant_name"]
cur = mysql.connection.cursor()
cur.execute(
"INSERT INTO tenant_details(Tenant_name) VALUES (%s)", [Tenant])
mysql.connection.commit()
cur.close()
return "successfully inserted"
return render_template("index.html")
if __name__ == '__main__':
tenant_app.run()
Here is html code
<html>
<head>
</head>
<body>
<form method="post">
<h1 style="text-align: center">TENANTS OF GILBERT</h1><br>
Enter your name :<input type="text" name="tenant_name">
<input type="submit" value="ADD" >
<!-- <input type="submit" value="EDIT">
<input type="submit" value="DELETE"> -->
</form>
</body>
</html>
am expecting a entery of tenant name into database message should be displayed as successfully inserted