Я пытаюсь вставить данные в базу данных MYSQL, когда я пробую свою программу. В следующей строке выдается сообщение об ошибке «Недостаточно аргументов для форматирования строки».
ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB se
rver version for the right syntax to use near '%s)' at line 1
И мой код:
from flask import Flask, render_template, request
import mysql.connector
app = Flask(__name__, static_url_path="", static_folder="static")
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="railway"
)
mycursor = mydb.cursor()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/store',methods=['POST', 'GET'])
def store():
if request.method=='POST':
name=request.form['name']
mycursor.execute("""INSERT INTO railway (name) VALUES (%s)""",(name))
mydb.commit()
return "record inserted."
else:
return "s"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)