I am making a small project that uses a database, when user i creating a account, i need to check the database if the username is available.
My code is something like this:
<code>db = mysql.connector.connect(
host="localhost",
user="user",
password="password",
database = "users"
mycursor = db.cursor()
username = input("Username: ")
mycursor.execute("SELECT username FROM users")
for x in mycursor:
if x == username:
print(True)
else:
print(False)
</code>
<code>db = mysql.connector.connect(
host="localhost",
user="user",
password="password",
database = "users"
mycursor = db.cursor()
username = input("Username: ")
mycursor.execute("SELECT username FROM users")
for x in mycursor:
if x == username:
print(True)
else:
print(False)
</code>
db = mysql.connector.connect(
host="localhost",
user="user",
password="password",
database = "users"
mycursor = db.cursor()
username = input("Username: ")
mycursor.execute("SELECT username FROM users")
for x in mycursor:
if x == username:
print(True)
else:
print(False)
I saw some similar questions to this, but they either arent with python, they arent working for me or i just dont understand them.
New contributor
Jaromír Staš is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.