私はPython 3.6のために死んだ単純なログインと登録スクリプトを書こうとしています。しかし、私はこのバグを取り除くことができません...私は登録するたびに、エラーはありませんが、私は再びそれを実行し、同じユーザー名を使用すると、それは既に存在するメッセージを表示しません... 私はあなたが実際に任意のコードを実行せずにfetchall()
を実行している...ここにコードがありますあまりにもちょうどので、私は(c.fetchall()
を使用して)そこにあるものを見ることができ、出力全体のDBにSQLite 3/Python3.6 - 登録とログインスクリプト(sqlとpython初心者)
import sqlite3 as sql, os
def dirCheck():
exDir=False
for count in os.listdir():
if count == 'sql':
exDir=True
if exDir == False:
os.mkdir('sql')
dirCheck()
cnct=sql.connect('./sql/usrAcc.db')
c=cnct.cursor()
def newTable():
c.execute('CREATE TABLE IF NOT EXISTS users(username TEXT, password TEXT)')
newTable()
f=False
t=True
valid=f
taken=f
def credsWrite(username, password):
c.execute('INSERT INTO users(username, password) VALUES (?, ?)',
(username, password))
cnct.commit()
for row in c.fetchall():
print(row)
c.close
cnct.close
def userReg():
global valid, taken
print(fancy[1])
while not valid:
print(fancy[3])
username=str(input('>> '))
for row in c.fetchall():
if str(username) == str(row[0]):
print('Sorry, but that username has already been taken...\nPlease enter another\n> ')
taken=True
if not taken:
print(fancy[4])
password=str(input('>> '))
valid=True
credsWrite(username,password)
fancy=["""
================
| SQL LOGIN TEST |
================
""","""
==========
| REGISTER |
==========
""","""
=======
| LOGIN |
=======
""","""
================
| ENTER USERNAME |
================
""","""
================
| ENTER PASSWORD |
================
"""]
def startUp():
print(fancy[0])
chosen=False
while not chosen:
opt=int(input('\n Please choose one of the options below:\n\n-> Register for a new account [1]\n-> Login to an existing account [2]\n\nPlease type a number...\n\n>> '))
if opt==1:
userReg()
chosen=True
elif opt==2:
login()
chosen=True
else:
print('\n\nPLEASE TYPE EITHER 1 OR 2...\n ')
if __name__ == "__main__":
startUp()