0
import sqlite3
conn = sqlite3.connect('LeVinEmployee.db')
profile = input("Are you a user? y/n: ")
if profile == 'y':
    login = input("Enter login name: ")
    #passw = input("Enter password: ")
    c = conn.cursor()
    c.execute("SELECT * FROM Employee WHERE Email = '" + login + "'")
    result = c.fetchone()
    if result[0] == 1:
         print(c.fetchall())
    else:
         print("not")

else:
    print("You are not a user")

What I am trying to do here is pretty simple. I am trying to create user login function. If user type 'y', program will simply ask to put login email. If user type correct email from database, print that customer information. if wrong, print 'not'. I am not sure what is wrong with my code. Can someone help me please?

1 Answer 1

2

As I understand, email is an unique field. And your query could return one record or nothing (None). Try

result = c.fetchone()
if result:  # result could be None or tuple (record)
     print(result)
else:
     print("not")

Also, such method of parameter pass is incorrect (insecure)

c.execute("SELECT * FROM Employee WHERE Email = '" + login + "'")

use

c.execute("SELECT * FROM Employee WHERE Email=?", login)

more info here.

Sign up to request clarification or add additional context in comments.

3 Comments

It works. Thanks alot. I assume if i want to check password, it will be the same right?
@Vincent Lynn You are welcome) Yes, it will be the same. Something like c.execute("SELECT * FROM Employee WHERE Email=? AND pass=?", login, pass)
Very helpful. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.