Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PythonMySQL编程错误:1064(42000),在使用Flask生成表单时_Python_Mysql_Forms_Flask Wtforms_Mysql Error 1064 - Fatal编程技术网

PythonMySQL编程错误:1064(42000),在使用Flask生成表单时

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

我试图使用Flask制作一个表单,并将表单的数据上传到MySQL数据库,在那里我遇到了这个错误

1064(42000):您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以获取第1行“%s”附近要使用的正确语法

我使用了以下代码:

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))}的用户中选择*)

编译器以这种方式显示无效语法的错误。编译器以这种方式显示无效语法的错误