i am a newbie
I want to prevent the duplicate usernames every time people do registration.
Here is my snipped code:
def submit(self):
    username_info = username.get()
    username_password = password.get()
    #connect to db
    db = mysql.connector.connect(host = 'localhost', user = 'root', password = '', database = 'user')
    #create a cursor
    mycursor = db.cursor()
    #insert to db
    sql = ("INSERT INTO useraccess (user_type, password) VALUES (%s, %s)")
    query = (username_info, username_password)
    mycursor.execute(sql, query)
    #commit
    db.commit()
    #create a messagebox
    messagebox.showinfo("Registration", "Successfully Register")
    #if username has been used
    find_user = ("SELECT * FROM useraccess WHERE user_type = ?")
    user_query = (username_info)
    mycursor.execute(find_user, user_query)
    #if (username == username_info):
    if mycursor.fetchall():
        messagebox.showerror("Registration", "The username chosen is already used. Please select another username")
    else:
        messagebox.showinfo("Registration", "Account Created!")
But every time I run it, although the username has been registered in the db, it only shows the successfully created messagebox and error:
ValueError: Could not process parameters.
Anyone can help me to solve this problem?
I believe the source of the problem is in the line
user_query = (username_info)
It should be
user_query = (username_info,)
The trailing comma is the syntactic difference between an expression in parentheses and a tuple.
Another issue with code is the query:
find_user = ("SELECT * FROM useraccess WHERE user_type = ?")
Which should be:
find_user = ("SELECT * FROM useraccess WHERE user_type = %s")
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With