Quantcast
Channel: MySQL Forums - Connector/Python
Viewing all articles
Browse latest Browse all 384

Check if a record exists (no replies)

$
0
0
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

Viewing all articles
Browse latest Browse all 384

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>