import pymysql
conn = pymysql.connect(
host = "127.0.0.1",
port = 3306,
user = "root"
password = "123321"
database = "homework"
)
cursor = conn.cursor(pymysql.cursors.DictCursor)
while True:
name = input('>>>用户名(q 退出)).strip()
if name =="q":break
pwd = input('>>>密码).strip()
#先判断是否重复
count= cursor.execute("select * from user where name = %s",(name,))
if count :
print('重复了”)
else:
#插入数据
count = cursor.execte("insert into user values(null ,%s,%s)
"(name,pwd))
if count:
print("注册成功”)
break
else:
print ("注册失败")
#提交数据
conn.commit()
cursor.close()
conn.close()