mysql 登录_PHP+MySQL网站开发实例——登录模块

f4720b05bceeb373a9c9d880c4b6d783.png

界面就是这样简单!html+css+js实现

html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>重症医学科信息管理系统</title>
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link href="./static/css/base.css" rel="stylesheet" type="text/css">
<link href="./static/css/login.css" rel="stylesheet" type="text/css">
<script src="./static/js/login.js" charset="utf-8"></script>
</head>
<body>

<div class="login">
<form action="login.php" method="post" id="form">
	<div class="logo"></div>
    <div class="login_form">
    	<div class="user">
        	<input class="text_value" value="" name="username" type="text" id="username">
            <input class="text_value" value="" name="password" type="password" id="password">
        </div>
        <button class="button" id="submit" type="submit">登录</button>
    </div>

    <div id="tip"></div>
    <div class="foot">
	Copyright &copy; 2019.Company 九饼 All rights reserved.
    </div>
    </form>
</div>
</body>
</html>

js

window.onload = function(){
  // alert("welcome");
  var form = document.getElementById('form');
  var username = document.getElementById('username');
  var password = document.getElementById('password');
  var tip = document.getElementById('tip');
  var submit = document.getElementById('submit');

  submit.onclick = function(){
    if(username.value.trim() == ""){
      tip.innerHTML = "<span style='color:red;'>工号不能为空!</span>";
      username.focus();
      return false;
    }
    if(password.value.trim() == ""){
      tip.innerHTML = "<span style='color:red;'>密码不能为空!</span>";
      password.focus();
      return false;
    }
  }

css(当然还有一些修改浏览器默认显示的reset.css base.css)

html, body { width: 100%; height: 100%; overflow: hidden; margin: 0; font-family: 'microsoft yahei'; background-image:url(../image/login_bg.jpg); }
html { _height: auto; _padding: 50px 0 0px; }

.login { width:640px; height:400px; position:absolute; left:50%; top:50%; margin-left:-320px; margin-top:-200px;}
.logo { background-image:url(../image/admin_logo.png); background-repeat:no-repeat; background-position: 30px center; height:150px;}
.login_form { height:80px; margin-left:auto; margin-right:auto; width:600px;}
.login_form .user{ background-image:url(../image/login_name_bg.jpg); width:540px; height:80px; float:left;}
.login_form .button { background:url(../image/login_button.jpg); width:50px; background-repeat:no-repeat; background-position:left center; height:54px; float:left; display:block; text-indent: -9999px; border:none; margin-top:10px; position:relative}
.login_form .text_value { float:left; margin-left:17px; padding-left:10px; padding-right:10px; margin-top:15px; width:225px; height:50px; line-height:50px; font-size:16px; color:#666; font-weight:bold; border:none; background-color:#f5f6f7}
.foot { padding-top:30px; text-align:center; color:#FFF; padding-right:80px;}
#tip { padding-top:10px; color:#FFF;   background-image:none; text-align:center; padding-right:80px; font-size:14px;}

php

<?php
// 开启session
session_start();
// 如果已经登录,跳转到首页
if(isset($_SESSION['user'])&&!empty($_SESSION['user'])){
	header('Location:index.php');
	exit;
}
// 处理提交的表单
if (!empty($_POST['username'])) {
	$username = trim($_POST['username']);
	$password = trim($_POST['password']);
	if(!$username){
		echo '工号不能为空!';
		exit;
	}
	if(!$password){
		echo '密码不能为空!';
		exit;
	}
	// 数据库连接
	$con = new mysqli("127.0.0.1","root","20180607","crrt");
	if($con->connect_errno){
		echo '数据库连接失败:('.$con->connect_errno.')'.$con->connect_error;
		exit;
	}
	$sql = "SELECT * FROM user WHERE user_number = {$username}";
	$obj = $con->query($sql);
	$result = $obj->fetch_assoc();
	// 判断工号是否存在
	if ($result) {
		// 判断密码是否正确
		if ($result['user_password'] === $password) {
			$_SESSION['user'] = $result;
			header('Location:index.php');
			exit;
		}
		else {
			echo "密码错误";
			exit;
		}
	}
	else {
		echo '工号错误!';
		exit;
	}
}
?>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值