0

I am trying to make a login system that uses a SQL database to store users' info. I keep running into issues as whenever I bring in data from the database it comes in looking like this (data,). I want just the data within the database, so in this example data.

def getDatabaseInfo():
"""This function gets all the user information from the database"""
mycursor.execute("SELECT userId FROM users")
#Puts all userID's into the userID list. This list is then used to start creating
#objects once the user class is made
for x in mycursor:
    userID.append(x)


for x in userID:
    newUser = User(x)
    mycursor.execute("SELECT username FROM users WHERE userId = " + str(x[0]) + "")
    for y in mycursor:
        newUser.setusername(y)

    mycursor.execute("SELECT password FROM users WHERE userId = " + str(x[0]) + "")
    for y in mycursor:
        newUser.setpassword(y)

    mycursor.execute("SELECT first_name FROM users WHERE userId = " + str(x[0]) + "")
    for y in mycursor:
        newUser.setfirst_name(y)

    mycursor.execute("SELECT last_name FROM users WHERE userId = " + str(x[0]) + "")
    for y in mycursor:
        newUser.last_name = y

    mycursor.execute("SELECT appetizer FROM users WHERE userId = " + str(x[0]) + "")
    for y in mycursor:
        newUser.appetizer = y

    #Stores instance into dictionary with username as key
    users[newUser.username] = newUser
    
    #prints information
    newUser.print_user_info()

I am sure the code above is really inefficient but it's at least working at this point minus the formatting looking bad.

  • Briefly: `(data,)` is a tuple containing a single object, `data`. Just access the tuple's first element. – TigerhawkT3 Nov 28 '21 at 05:53
  • You should learn about the basic [types](https://docs.python.org/3/library/stdtypes.html) in Python and how to use them. – Klaus D. Nov 28 '21 at 06:14

0 Answers0