フィールドが存在するかどうかを確認するためにスレッドをたくさん見ましたが、少し混乱しています。誰かが私にそれが存在するかどうかをチェックし、可変である入力。Python SQLite3フィールド== varible
私のコードは、これまで
import sqlite3
import datetime
import smtplib
now = datetime.datetime.now()
conn = sqlite3.connect("accounts.db")
c = conn.cursor()
def register():
username = input("Username: ")
password = input ("Password: ")
date = now.strftime("%d-%m-%Y %H-%M")
adminlevel = 0
c.execute("""INSERT INTO accounts
(username,password,date,adminlevel)
VALUES(?,?,?,?)""",(username,password,date,adminlevel))
conn.commit()
print("You have succesfully registered at " + date, "An email has been sent to you with your information!")
menu()
from getpass import getpass
def login():
def loggedin():
if adminlevel > 0:
print("Hello There Admin!")
print("Commands: ")
else:
print("Hello there {}".format(username))
print("Commands: Name, Date, Friend, Logout")
adminlevel = 0
username = input("Please enter your username: ")
password = getpass("Please enter your password: ")
admin = c.execute("select 1 from accounts where adminlevel > 0")
c.execute("select 1 from accounts where username = ? and password = ?", (username, password))
if c.fetchone():
print('Hello there! {}'.format(username))
loggedin()
else:
print("Username and Password Not Found!")
login()
def menu():
print("="*40)
print("Login & Registration System")
print("="*40)
choice = input("Login or Register? ")
if choice == "register":
register()
elif choice == "login":
login()
menu()
'login()'関数の意味ですか?あなたはあなたの質問を明確にするためにもっと努力するべきです - 疑問が何であるかを理解するためにすべてのコードを読む必要はありません。 – mhawke
'def info():'は何もしません(グローバル変数はそれらを使う関数で 'global'宣言されるべきです)' username == username: 'は常に真です。' username'が定義されていれば、です。 – jDo
今、それを取り除いても心配しないでください、私は私の答えがあります:) –