I would like to ask an question like this It makes me Struggle. Please Help
How Can I Fix This error While Updating the Table
Here’s The code
Heres The Update Code
def update():
databases = mysql.connector.connect(
host ="localhost",
user = "userdata",
password = "",
database = "facerecog"
)
conn = databases.cursor()
conn.execute("UPDATE record set names=%s, course_year=%s, position=%s"(t4.get(),t5.get(),t6.get()))
databases.commit
databases.close
messagebox.showinfo("NOTICE", "UPDATED SUCCESSFULLY")
And here The data show Selected Shows on my text box
def showtable(tree):
viewinfo = tree.focus()
data = tree.item(viewinfo)
row = data['values']
t4.set(row[0])
t5.set(row[1])
t6.set(row[2])
And Here’s The button
updatebutton = tk.Button(t, text = "Update Data", command =update)
updatebutton.configure(font = ('Cooper', 13, 'bold'), bg = 'sky blue', fg = 'black')
updatebutton.place(x=560, y=360)
t.bind("<ButtonRelease-1>",showtable)
And then It Appears error Like this
py:347: SyntaxWarning: 'str' object is not callable; perhaps you missed a comma?
conn.execute("UPDATE record set names=%s, course_year=%s, position=%s"(t4.get(),t5.get(),t6.get()))
3
Answers
I think the code should be a string formatting, it is missing
%
:Modulo string formatting is kind of ancient, I prefer f-strings:
The error is telling you what to fix: it seems like you have invalid format.
The docs that I was able to find for the
mysql.connector
seems to confirm that you would separate formatted arguments with a comma,
as I had initially suspected. By the way, the log methods in the pythonlogging
module work the same way as well, which is pretty handy.So in your case, I’d replace that line:
where
update_stmt
is defined aswith the following line:
As an aside, you’ll have noticed that the error you got is actually very helpful in this case:
Which is actually the very thing we needed to do to resolve the error.