Python实现登陆注册代码小记(带数据库)

import pymysql
db=pymysql.connect(host=‘localhost’,user=‘root’,passwd=‘123’,port=3306,db=‘test’,charset=‘utf8’)
cursor=db.cursor()
#这是注册
def zhuce():
print(“欢迎来到登陆页面”)
name = input(“请输入用户名”)
password = input(“请输入密码”)
sex = input(“请输入性别”)
age = input(“请输入年龄”)
try:
cursor.execute(“insert into pen values(null,’%s’,’%s’,’%s’,%d)”
% (name, password, sex, int(age)))
db.commit()
print(“注册成功”)
except:
print(“添加失败”)
# 登陆
def login():
print(“欢迎登陆”)
name=input(“请输入用户名:”)
password=input(“请输入密码:”)
num=cursor.execute(“select * from pen where user=’%s’ and pass=’%s’”
%(name,password))
if(num>=1):
print(“登陆成功”)
login_n=int(input(“按1查询数据,2返回首页”))
if(login_n1):
print(“欢迎来到查询页面”)
num = cursor.execute(“select * from pen”)
r=cursor.fetchall()
print(“序号\t账号\t性别\t年龄”)
for v in r:
print("%d\t%s\t%s\t%d" %(v[0],v[1],v[3],v[4]))
n = int(input(“按1修改,按2删除”))
if(n
1):
print(“欢迎来到修改页面”)
id = int(input(“请输入要修改的编号”))
password = input(“请输入要修改的密码”)
sex = input(“请输入要修改的性别”)
age = int(input(“请输入要修改的年龄”))
cursor.execute(“update pen set pass=’%s’,sex=’%s’,age=%d”
" where id=%d" %(password,sex,age,id))
cursor.commit()
print(“修改成功”)
elif(n==2):
print(“欢迎来到删除页面”)
id=int(input(“请输入要删除的编号”))
cursor.execute(“delete from pen where id=%d” %(id))
cursor.commit()
print(“删除成功”)
else:
print(“登陆失败”)
#这是首页
while(True):
print(“欢迎来到xxx系统”)
index_n = input(“按1进行登陆,按2进行注册,按3退出”)
if index_n == “1”:
login()
elif index_n == “2”:
zhuce()
elif index_n == “3”:
print(“已退出,再见”)
break

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值