【问题标题】:Not all parameters were used in the SQL statement - Python, MySQL并非所有参数都在 SQL 语句中使用 - Python、MySQL
【发布时间】:2019-09-28 17:24:03
【问题描述】:

我收到此代码错误。编程错误是语句中并未使用所有参数。我认为这是关于更新声明,但我不知道真正的问题是什么

定义编辑配置文件():

username1 = username_verify.get()
password1 = password_verify.get()
full_name1 = full_name_verify.get()
faculty1 = c.get()
position1 = position_verify.get()
email1 = email_verify.get()
room_no1 = room_no_verify.get()

if full_name1 == "" and faculty1 == "" and  position1 == "" and email == "" and room_no1 == "":
     Label(text="").pack()
     time.sleep(1)
     Label(text="Please complete your profile", fg="red", width=50).place(x=250,y=380)

else:
    profile_upd = "UPDATE profile SET Faculty = %s AND Position = %s AND Email = %s AND  Room_NO = %s WHERE username =%s"
    user1 = (full_name1, faculty1, position1, email1, room_no1,username1)
    mycursor.execute(profile_upd, user1)
    mydb.commit()
    Label(text ="CHANGES SAVED SUCCESFULLY!!", fg = "green",width=50).place(x=250,y=380)

the traceback

【问题讨论】:

    标签: python mysql


    【解决方案1】:

    错误显示需要的参数数量与元组user1中的参数数量不匹配。

    在元组 user1 中,有 6 个元素,但您的更新命令只有 5 个 %s。看来您在更新命令中错过了full_name1

    更新命令应该是这样的:

    profile_upd = "UPDATE profile SET Full_Name = %s AND Faculty = %s AND Position = %s AND Email = %s AND  Room_NO = %s WHERE username =%s"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-12
      • 1970-01-01
      • 2017-07-25
      • 1970-01-01
      • 2021-03-03
      • 2016-04-04
      • 2019-09-09
      相关资源
      最近更新 更多