Why can't I compare these form variables using python in my mysql query?
Question: I am trying to check for a string that is being passed from a form in an html
page. So the form picks up the user name and then checks the database if it
already has been made. If it hasn't, it goes ahead and creates it. My errors
are in the part of the logic that looks up that user name.

Note, I have commented out some areas where various errors have popped up:

    
    
    import mysql.connector
    import web
    
    from mysql.connector import Error
    import cgi, cgitb
    
    cgitb.enable()
    
    conn = mysql.connector.connect(host='localhost', database='database', user='root', password='root')
    cursor = conn.cursor()
    form = cgi.FieldStorage()
    username = form.getvalue('username')
    password = form.getvalue('password')
    
    
    # check_existence = """
    #   SELECT username FROM members WHERE username = '%s'
    # """
    
    check_existence = """
        SELECT username FROM members WHERE username = %s
    """
    
    # cursor.execute(check_existence, username)
    #    "Wrong number of arguments during string formatting")
    
    
    cursor.execute(check_existence, (username))
    
    #   ^pushes down to con.commit
    # cursor.execute(check_existence, (username,))
    #    ^wrpmg number of arguments during string formatting
    #   with comma, the error is in commit, with comma, its in execute
    
    
    conn.commit()  
    
    matches = cursor.rowcount()
    

Now the error is pointing to conn.commit. Though this is depending on the
syntax, sometimes it points to the line above it. Error:

    
    
    =>  203 conn.commit()  
    <class 'mysql.connector.errors.InternalError'>: Unread result found. 
          args = (-1, 'Unread result found.', None) 
          errno = -1 
          message = '' 
          msg = 'Unread result found.' 
    


Answer: In my limited experience, commit() is only used to save (commit) updates to
the database. It looks like you're executing a select query, but doing nothing
with the results, and the error is related to that. Try moving the commit to
the end, or doing away with it. Try using/doing something with the results
stored in the cursor. I believe the latter is the solution.

