从sqllite提取用户信息3

发布于 2025-01-26 10:28:06 字数 389 浏览 2 评论 0原文

我正在使用python和sqllite3创建银行GUI。

在代码中的这一点上,用户已登录。我正在尝试显示与用户关联的信息。每个用户名都是唯一的 - 因此,在这里,我试图获取与“ user_name2”相关的名称,而“ user_name2”只是以前用于登录的用户名。它返回光标对象。我该如何简单地将值打印到我的GUI中?

get_name = cur.execute(f"SELECT name FROM all_accounts WHERE username = '{user_name2}'")

Label(user_info, text=f"Name:{get_name}", font="times 13").grid(row=0, sticky=NW, pady=10, padx=30)

I am creating a banking GUI using python and SQLLITE3.

At this point in the code, the user has logged in. I am trying to display the information associated with the user. Every username is unique--so here I am attempting to get the name that is associated with "user_name2" which is just the username that had been previously used to login. It returns a cursor object. How can I get it to simply print the value into my GUI?

get_name = cur.execute(f"SELECT name FROM all_accounts WHERE username = '{user_name2}'")

Label(user_info, text=f"Name:{get_name}", font="times 13").grid(row=0, sticky=NW, pady=10, padx=30)

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

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

发布评论

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

评论(1

负佳期 2025-02-02 10:28:06

这是我的答案

cur.execute(f"SELECT name FROM all_accounts WHERE username = '{user_name2}'")
name = cur.fetchone()
if not name is None:
    Label(user_info, text=f"Name:{name}", font="times 13").grid(row=0, sticky=NW, pady=10, padx=30)
else:
    print("No user found!")

安全警告,

如果您不过滤user_name2,坏人将对数据库进行SQL注入攻击。您可以咨询

最简单的方法是使用Plaecholder, python很容易

cur.execute("SELECT name FROM all_accounts WHERE username = ?", user_name2)
name = cur.fetchone()
if not name is None:
    Label(user_info, text=f"Name:{name}", font="times 13").grid(row=0, sticky=NW, pady=10, padx=30)
else:
    print("No user found!")

Here is my answer

cur.execute(f"SELECT name FROM all_accounts WHERE username = '{user_name2}'")
name = cur.fetchone()
if not name is None:
    Label(user_info, text=f"Name:{name}", font="times 13").grid(row=0, sticky=NW, pady=10, padx=30)
else:
    print("No user found!")

Security WARNING

If you do not filter user_name2, bad guys will conduct SQL injection attack to your database. You can consult this

The simplest method is using plaecholder, which is very easy in python

cur.execute("SELECT name FROM all_accounts WHERE username = ?", user_name2)
name = cur.fetchone()
if not name is None:
    Label(user_info, text=f"Name:{name}", font="times 13").grid(row=0, sticky=NW, pady=10, padx=30)
else:
    print("No user found!")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文