使用Python QT和MySQL数据库将数据插入MySQL

发布于 2025-01-28 10:57:47 字数 985 浏览 3 评论 0原文

我正在努力从我尝试的数据库中插入或检验数据,并观看了许多教程,但是每次停止cur.execute()时。我发现问题在于self.firstnmae.text()funtion之类的值

def SignupFunction(self):
    try:
        
        connection = pymysql.connect(host=cr.host, user=cr.user, password=cr.password, database=cr.database)
        
        cur = connection.cursor()
        
        cur.execute("insert into users (FirstNmae , LastName, Email,Password , Confirm_Paswword ,Answer) value( %s, %s, %s, %s, %s, %s)",
            (
                self.FirstNmae.text(),
                self.LastName.text(),
                self.Email.text(),
                self.Password.text(),
                self.Confirm_Paswword.text(),
                self.Answer.text()
            ))
        
        connection.commit()
        
        connection.close()
        self.labelResult.setText("Data Inserted ")
    except Exception as e:
        self.labelResult.setText("Error Inserting Data")

I'm struggling to insert or retrive data from database I tried and I watched many tutorials but every time it stops in cur.execute(). i found problem is in the value like self.FirstNmae.text() funtion stop here

def SignupFunction(self):
    try:
        
        connection = pymysql.connect(host=cr.host, user=cr.user, password=cr.password, database=cr.database)
        
        cur = connection.cursor()
        
        cur.execute("insert into users (FirstNmae , LastName, Email,Password , Confirm_Paswword ,Answer) value( %s, %s, %s, %s, %s, %s)",
            (
                self.FirstNmae.text(),
                self.LastName.text(),
                self.Email.text(),
                self.Password.text(),
                self.Confirm_Paswword.text(),
                self.Answer.text()
            ))
        
        connection.commit()
        
        connection.close()
        self.labelResult.setText("Data Inserted ")
    except Exception as e:
        self.labelResult.setText("Error Inserting Data")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荭秂 2025-02-04 10:57:47

你好朋友,我无法发表评论,所以我将作为您的代码中的答案发布,您是新开发人员,您的功能很好,我认为问题在您的数据库中,如果您是数据库,请查看数据库错过了一些东西,或者你写的属性像firstnmae

hello friend i'm not able to comment so i will post as answer from your code you are a new developer , your function is good there are no problem in it i think that the problem is in you database look at the database if you are missed something or you mess write attributes like FirstNmae

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文