python delete(0、end)_从用户获取数据时,Python-mysql的DELETE语句不删除行

用户在尝试使用 Python 连接 MySQL 数据库并根据输入的 Email、Website 和 Password 删除特定记录时遇到问题。代码显示无错误且提示记录已删除,但实际上数据库中记录未被删除。即使使用了 `commit()` 方法,也无法提交删除操作。
摘要由CSDN通过智能技术生成

I have a database named accounts_1 amd a table in it named myrecords, this is that database and i want to delete a particular record as user inputs in the variable Email, Website and Password. I have a code below, it shows no error and also the message Record deleted but nothing is deleted in my mysql database, even i already used commit() but still noting is commited. Please help me out of this.

删除功能如下:

def delrec():

newroot=Toplevel()

def record():

Email = email.get()

Password = passwd.get()

Website = website.get()

delete="delete from myrecords where Website='%s' and Email='%s' and Password='%s'" %(Website,Email,Password)

if(Website !="" and Email !="" and Password !=""):

mycursor.execute(delete)

mydb.commit()

messagebox.askokcancel("

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以按照以下步骤设置删除按钮删除treeview和mysql数据库中的某一: 1. 在TreeView中添加删除按钮的列,可以使用tkinter库中的Button控件实现。 2. 给删除按钮绑定一个点击事件,当用户点击该按钮,触发对应的函数。 3. 在函数中获取当前选中的,可以使用TreeView中的selection()方法。 4. 从选中的中获取到需要删除的数据的主键值。 5. 使用mysql-connector-python模块连接到数据库,并且执删除语句。 6. 从TreeView中删除对应的。 下面是一个示例代码,可以参考一下: ```python import mysql.connector from tkinter import * from tkinter import ttk # 创建数据库连接 conn = mysql.connector.connect( host="localhost", user="root", password="password", database="test_db" ) # 创建TreeView root = Tk() tree = ttk.Treeview(root) tree.pack() # 在TreeView中添加删除按钮的列 tree["columns"] = ("name", "age", "action") tree.column("#0", width=0, stretch=NO) tree.column("name", width=100, anchor=W) tree.column("age", width=100, anchor=W) tree.column("action", width=100, anchor=W) tree.heading("#0", text="", anchor=W) tree.heading("name", text="Name", anchor=W) tree.heading("age", text="Age", anchor=W) tree.heading("action", text="Action", anchor=W) # 添加数据到TreeView cursor = conn.cursor() cursor.execute("SELECT * FROM user") for row in cursor.fetchall(): tree.insert("", END, text="", values=row[:-1] + ("Delete",)) # 删除函数 def delete(): # 获取当前选中的 selection = tree.selection() # 获取需要删除的数据的主键值 for item in selection: pk = tree.item(item, "values")[0] # 连接数据库,并且执删除语句 cursor = conn.cursor() cursor.execute("DELETE FROM user WHERE id=%s", (pk,)) conn.commit() # 从TreeView中删除对应的 tree.delete(item) # 给删除按钮绑定点击事件 tree.bind("<Button-1>", lambda event: delete() if tree.identify_region(event.x, event.y) == "cell" else None) root.mainloop() ``` 在这个示例中,我们创建了一个具有删除按钮的TreeView,当用户点击删除按钮,会触发delete()函数。在该函数中,我们首先从选中的中获取需要删除的数据的主键值,然后连接到mysql数据库,并且执删除语句。最后,我们从TreeView中删除对应的

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值