PythonMySQL编程错误:1064(42000),在使用Flask生成表单时
我试图使用Flask制作一个表单,并将表单的数据上传到MySQL数据库,在那里我遇到了这个错误 1064(42000):您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以获取第1行“%s”附近要使用的正确语法 我使用了以下代码:PythonMySQL编程错误:1064(42000),在使用Flask生成表单时,python,mysql,forms,flask-wtforms,mysql-error-1064,Python,Mysql,Forms,Flask Wtforms,Mysql Error 1064,我试图使用Flask制作一个表单,并将表单的数据上传到MySQL数据库,在那里我遇到了这个错误 1064(42000):您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以获取第1行“%s”附近要使用的正确语法 我使用了以下代码: if request.method=="POST" and form.validate(): username=form.username.data email=form.email.data password
if request.method=="POST" and form.validate():
username=form.username.data
email=form.email.data
password=sha256_crypt.encrypt((str(form.password.data)))
c,conn=connections()
x = c.execute("SELECT * FROM users WHERE username = (%s)",
(thwart(username)))
if int(x) > 0:
flash("That username is already taken, please choose another")
return render_template('register.html', form=form)
else:
c.execute("INSERT INTO users (username, password, email, tracking) VALUES (%s, %s, %s, %s)",
(thwart(username), thwart(password), thwart(email), thwart("/introduction-to-python-programming/")))
conn.commit()
flash("Thanks for registering!")
c.close()
conn.close()
您没有设置什么
%s
是错误的,应该是这样的
x=c.execute(“从用户名=(%s)的用户中选择*”%
(thwart(用户名)))
或
x=c.execute(f“从用户名={thwart(username))}的用户中选择*)
您没有设置什么%s
是错误的,应该是这样的
x=c.execute(“从用户名=(%s)的用户中选择*”%
(thwart(用户名)))
或
x=c.execute(f“从用户名={thwart(username))}的用户中选择*)
编译器以这种方式显示无效语法的错误。编译器以这种方式显示无效语法的错误