Hello!
I am writing a python function to check if a user exists in a database. This is the code:
def searchUser():
print 'Which user are you looking for?'
Username = raw_input('> ')
sql = '''IF EXISTS (SELECT * FROM Users WHERE Username = %s)
PRINT 'User exist'
ELSE
PRINT 'User does not exist'''
cursor.execute(sql, (Username))
result = cursor.fetchall()
However, when I run it it returns a syntax error. Can anyone help me to write it properly?
Cheers!
Dani
I am writing a python function to check if a user exists in a database. This is the code:
def searchUser():
print 'Which user are you looking for?'
Username = raw_input('> ')
sql = '''IF EXISTS (SELECT * FROM Users WHERE Username = %s)
PRINT 'User exist'
ELSE
PRINT 'User does not exist'''
cursor.execute(sql, (Username))
result = cursor.fetchall()
However, when I run it it returns a syntax error. Can anyone help me to write it properly?
Cheers!
Dani