为什么数据库的用户名和PIN部分未被识别?

发布于 2025-02-05 18:11:03 字数 1166 浏览 2 评论 0原文

# PHASE 2 (With Database) SQLite 3 

# Define Connection and Cursor 
connection = sqlite3.connect('Bank_Users.db')
cursor = connection.cursor()

# Create Users Table 
command1 = """ CREATE TABLE IF NOT EXISTS 
bank(pin INTEGER PRIMARY KEY , username text )"""
cursor.execute(command1)

# Add to Users/Bank
cursor.execute("INSERT INTO bank VALUES (7620, 'Kailas Kurup')")
cursor.execute("INSERT INTO bank VALUES (4638, 'Bethany Watkins')")
cursor.execute("INSERT INTO bank VALUES (3482, 'John Hammond')")
cursor.execute("INSERT INTO bank VALUES (3493, 'Melissa Rodriguez')")
cursor.execute("INSERT INTO bank VALUES (9891, 'Kevin Le')")

# Get Results / Querying Database
cursor.execute("SELECT username, pin FROM bank")
results = cursor.fetchall()
print(results)

# Check Database User Info  
def read_from_db():
    for row in cursor.fetchall():
        if username in row: 
            if pin in row: 
                print ("Success")
        else: 
            print("Invalid Pin")

**我正在尝试根据输入的用户名和PIN检查数据库。例如,如果输入了7620和Kailas Kurup以外的用户名和PIN,它将返回“无效”。但是我的代码无法识别,并且“用户名”和“ PIN”下有弯曲的线条。为什么会发生这种情况以及如何解决?我正在使用Visual Studio代码(VSCODE)。

# PHASE 2 (With Database) SQLite 3 

# Define Connection and Cursor 
connection = sqlite3.connect('Bank_Users.db')
cursor = connection.cursor()

# Create Users Table 
command1 = """ CREATE TABLE IF NOT EXISTS 
bank(pin INTEGER PRIMARY KEY , username text )"""
cursor.execute(command1)

# Add to Users/Bank
cursor.execute("INSERT INTO bank VALUES (7620, 'Kailas Kurup')")
cursor.execute("INSERT INTO bank VALUES (4638, 'Bethany Watkins')")
cursor.execute("INSERT INTO bank VALUES (3482, 'John Hammond')")
cursor.execute("INSERT INTO bank VALUES (3493, 'Melissa Rodriguez')")
cursor.execute("INSERT INTO bank VALUES (9891, 'Kevin Le')")

# Get Results / Querying Database
cursor.execute("SELECT username, pin FROM bank")
results = cursor.fetchall()
print(results)

# Check Database User Info  
def read_from_db():
    for row in cursor.fetchall():
        if username in row: 
            if pin in row: 
                print ("Success")
        else: 
            print("Invalid Pin")

** I'm trying to check the database based on the username and pin entered. For example if a username and pin other than 7620 and Kailas Kurup was entered, it would return "Invalid". But my code is going unrecognized and there are squiggly lines under "username" and "pin". Why is this happening and how do I fix it? I am using visual studio code (VScode).

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文