lundi 13 avril 2015

Python SQLite User query not validating

I am writing a python function that takes an input from a user, searches for it in a database and then checks the input against the return result and if correct proceeds with the program and if incorrect asks the user to re-enter. This doesn't work however. When a user enters something it just says it is incorrect as per my program. Here is the code:



def TakeOutItem():
Serial = input("Please enter the serial number of the music you are taking out: ")
SerialN = int(Serial,)
with sqlite3.connect("school.db") as db:
cursor = db.cursor()
cursor.execute("SELECT SerialNo FROM Music WHERE SerialNo=?",(SerialN,))
data = cursor.fetchone()
if SerialN == data:
DateOut = date.today()
DateIn = date.today() + timedelta(days=30)
cursor.execute('SELECT Name FROM Music WHERE SerialNo=?', Serial)
NameofMusic = cursor.fetchone()
cursor.execute('SELECT StudentID FROM Student WHERE username=?', student_login(username))
StudentID = cursor.fetchone()
cursor.execute('INSERT INTO MusicLoan VALUES (?,?,?,?,?)', DateOut, DateIn, Music, NameofMusic, StudentID)
print("Item taken out successfully")
student_menu()

else:
print("Incorrect Serial Number please try again")
TakeOutItem()


and this is the error screen



What would you like to do?

1. Take out item

2. Return item

3. Exit

Please select an option number: 1

Please enter the serial number of the music you are taking out: 01

Incorrect Serial Number please try again

Please enter the serial number of the music you are taking out:


How can I fix this error??


Aucun commentaire:

Enregistrer un commentaire