Reputation: 489
I am working on this Python Credits on your account system, but it appears my last for loop isn't running leading to a time_set not being defined. Does anybody know why my last for loop isn't running. Database details have been removed for security reasons. Here is my code:
from time import sleep
import MySQLdb
db = MySQLdb.connect(host="", # your host, usually localhost
user="", # your username
passwd="", # your password
db="") # name of the data base
cursor = db.cursor()#Defines a cursor allowing me to execute SQL commands
def timer(time, _print=False):
if time == 0:
cursor.execute("SELECT * FROM Accounts WHERE Username='{0}';".format(name))
cursor.execute("UPDATE Accounts SET Credits = 0 WHERE Username = '{1}';".format(creds, name))
return ''
else:
if _print: print time
sleep(1)
return timer(time - 1, _print)
name = raw_input("What username would you like to add credits to?:")
cursor.execute("SELECT * FROM Accounts WHERE Username='{0}';".format(name))
creds = input("How many credits would you like to add to the account?")
for test in cursor.fetchall():
creds = creds + test[3]
cursor.execute("UPDATE Accounts SET Credits = {0} WHERE Username = '{1}';".format(creds, name))
for row in cursor.fetchall():
time_set = creds * 60
print time_set
timer(time_set, True)
Upvotes: 1
Views: 111
Reputation: 489
I have seemed to have figured out the problem. I realized that the second for loop is completely unnecessary since I am just calculating the credits into minutes. So I removed
for row in cursor.fetchall():
time_set = creds * 60
print time_set
and replaced it with
time_set = creds * 60
Upvotes: 0
Reputation: 1252
It appears that you are trying to pull rows from an UPDATE query, which will get you nowhere since UPDATE does not return any rows.
Upvotes: 1