"""
save image.py
二进制文件存储演示
"""
import pymysql
"""
写操作实例
"""
#链接数据库
db = pymysql.connect(host='localhost',
port=3306,
user='root',
password='123456',
database='stu',
charset='utf8')
#获取游标(操作数据库,执行sql语句)
cur = db.cursor()
print("输入1注册,2登陆")
choice = input("输入选择:")
if choice == "1":
"""判断用户是否存在"""
username = input("请输入用户名:")
password = input("请输入密码:")
sql = "select * from user where name = %s"
cur.execute(sql,[username])
if cur.fetchone():
print('用户已经存在,重新输入')
else:
sql = "insert into user (name,password) values \
(%s,%s)"
cur.execute(sql,[username,password])
print('注册成功')
elif choice == "2":
username = input("请输入用户名:")
password = input("请输入密码:")
sql = "select * from user where name = %s and password = %s"
cur.execute(sql,[username,password])
if cur.fetchone():
print('登陆成功')
else:
print('用户名或者密码错误')
#关闭数据库
cur.close()
db.close()
pymysql编写注册登陆程序
最新推荐文章于 2024-08-15 01:26:58 发布