Python/MySQL - Error 1064, can't figure it out -
i've been trying find out causes error. believe in last query database. i've marked comments.
this error has been giving me headache past 30 minutes.
import mysqldb import time # create database connection db = mysqldb.connect(host="******", user="******", passwd="*****", db="*****") cur = db.cursor() # create query select ids cur.execute("select id users") clientarray = [] # loop on ids returned query, # save ids in clientarray row in cur.fetchall(): clientid = str(row[0]) clientarray.append(clientid) clientidinput = "" while true: # check , wait input clientidinput = raw_input("") if clientidinput in clientarray: # check see whether user signed in device cur.execute("select fitnessstatus users id=%s", (clientidinput)) data = cur.fetchone() if data[0] == false: cur.execute("update users set fitnessstatus='1' id=%s", (clientidinput)) checkintime = time.strftime('%y-%m-%d %h:%m:%s') checkoutid = raw_input("") if checkoutid == clientidinput: cur.execute("update users set fitnessstatus='0' id=%s", (clientidinput)) checkouttime = time.strftime('%y-%m-%d %h:%m:%s') print checkintime print checkouttime ### believe cause of error ### cur.execute("insert activities (id, machinename, checkin, checkout, clientid) values (null, cross trainer #5, %s, %s, %s)", (checkintime, checkouttime, clientidinput)) # send checkintime , checkouttime database
there syntax error in insert statement. try enclose string 'cross trainer #5' in single quotes:
cur.execute("insert activities (id, machinename, checkin, checkout, clientid) values (null, 'cross trainer #5', %s, %s, %s)", (checkintime, checkouttime, clientidinput))` luckily, statement enclosed in double quotes " no further change required :)
the error 1064 bit misleading. indicates, amongst others, abuse of reserved word. , indeed: cross reserved word.
Comments
Post a Comment