3
>>> print x 
 [(1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,)]

>>> for i in range(10):
...     if len(x)>0:
...             m = random.choice(x)
...             x.remove(m)
...             y = "%s" %m
...             z = int(y)
...             cur.execute("""UPDATE accounts SET column = 'YES' WHERE userid = %s""", (z, ))

This doesn't do anything though. When I view the accounts table, nothing's changed.

1 Answer 1

3

You need to commit the changes after the update:

db.commit()

where db is a database connection instance (the result of connect() call).

Also see: Database does not update automatically with MySQL and Python.

Sign up to request clarification or add additional context in comments.

2 Comments

sunnuva! I always forget that.. thank you so much sorry for this ignorant post
@user262064 You might want to create your cursor like with connection as cursor: immediately above the for loop. Then it will automatically commit() on success or rollback() on error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.