我的目标是防止我的数据库中的“学生”被更改,除非“老师”首先登录。我在创建一个可以做到这一点的旗帜时遇到了麻烦。 function1适用于学生,function2适用于教师
我想要的是:
教师首先登录>标志设置为允许学生登录>学生登录。
如果教师尚未登录。学生们不能。我该怎么做?
import MySQLdb as mysql
one = 0
mydb = mysql.connect(host= "192.168.1.10", user= "XXXX", passwd= "XXXX", db= "XXXX")
cur = mydb.cursor()
def function1():
with mydb:
receiver = raw_input("just waiting for an RFID: ")
cur.execute("SELECT * FROM users")
rows = cur.fetchall()
for row in rows:
if(receiver == row[4]):
cur.execute(" UPDATE users SET status= '1' where RFID =%s ",(receiver))
def function2():
with mydb:
receiver = raw_input("just waiting for an RFID: ")
cur.execute("SELECT * FROM users")
rows = cur.fetchall()
for row in rows:
if(receiver == row[4] and row[3] == 1):
cur.execute(" UPDATE users SET status = '1', status2= '1' where RFID = %s ",(receiver))