2020-11-26

登陆页面php与 mysql

1连接数据库

1.依照mysql界面 地址 用户密码
2.仓库
3.创建连接对象

<?php 
/* 
 依照mysql界面 地址 用户 密码
 仓库
 创建连接对象
 */
$addr='127.0.0.1';
$rootName='root';
$rootPwd='123456';
$db='db6';

$conn=new mysqli($addr,$rootName,$rootPwd,$db);
$conn->query('set names utf8');
?>

2数据库的调用

  1. 引入连接
  2. 接收参数
  3. 用户验证 查询
  4. 结果判断
  5. 签发通行证 session 先启动 写入
<?php 
/* 
 1  引入连接
 2  接收参数 
 3  用户验证  查询
 4  结果判断
 5  签发通行证  session   先启动  写入
 */
include'con0.php';
$usern=$_REQUEST['usern'];
$pwd=$_REQUEST['pwd'];
$url='../首页/music.php';
session_start();
$sql="select * from usern where usern='$usern' and pwd='$pwd'";
$res=$conn->query($sql);
if($res){
	$num=mysqli_num_rows($res);
	if($num>0){
		echo '登陆成功';
		Header("Location: $url");
		$_SESSION['usern']=$usern;
		$_SESSION['time']=time();
		}else{echo'账号或密码不正确';
			exit('登录失败!点击此处 <a href="login1.php">返回</a> 重试');
		}
}else{
	echo 'err';
}

$conn->close();
?>

3登陆页面

在这里插入图片描述

<?php error_reporting(0);?>
<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>登录</title>
	<style type="text/css">
		* {
			margin: 0;
			padding: 0;

		}

		.box {
			width: 400px;
			margin: auto;
			text-align: center;
			margin-top: 50px;
			box-shadow: 0 0 2px gray;
			background-color: rgb(245, 245, 245);
		}

		.box p {
			margin: 6px 0;
			height: 50px;
		}

		.top {
			width: 400px;
			height: 50px;
			background-color: rgb(230, 0, 0);
			box-shadow: 0 0 2px gray;

		}

		.top a {
			display: block;
			font-size: 24px;
			color: white;
			margin: 5px;
			width: 80px;
			height: 40px;
			text-decoration: none;
		}

		.top a:hover {
			background-color: rgb(200, 0, 0);
			box-shadow: 0 0 2px gray;

		}

		.L1 {
			/* background-color: green; */
			width: 150px;
			text-align: right;
			font-size: 16pt;
		}

		.L2 input {
			/* background-color: yellow; */
			height: 30px;
		}

		.L2 {
			font-size: 24px;

		}

		#sub {
			width: 60px;
			height: 40px;
		}
	</style>
</head>

<body>
	<div class="box">
		<div class="top">
			<a href="../首页/music.php" style="float: left">游客</a>
			<a href="register.html" style="float: right">注册</a>
			<h1 style="text-align: center;color: white">登陆</h1>
		</div>
		<form action="login.php" method="post">
			<table>
				<tr>
					<td class="L1">用户名:</td>
					<td class="L2">
						<input type="text" name="usern"/>
					</td>
				</tr>
				<tr>
					<td class="L1">密码:</td>
					<td class="L2">
						<input type="password" name="pwd"/>
					</td>
				</tr>
			</table>
			<!-- <p><input type="text" name="usern" placeholder="用户" style="margin-top: 20px;"/></p> -->
			<!-- <p><input type="password" name="pwd" placeholder="密码" /></p> -->
			<p><input type="submit" value="登陆" id="sub" /></p>
		</form>
	</div>
</body>

</html>
<?php
   session_start(); 
   $action='a';
if($_GET['action']=="logout"){  
    unset($_SESSION['usern']);  
	unset($_SESSION['pwd']);  
    // echo '注销登录成功!点击此处 <a href="login.html">登录</a>';  
	exit;  }
	
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值