php简单登录注册验证

列表页

<?php
//连接数据库
$db = new MySQLi('localhost','root','','z_1032');
!mysqli_connect_error() or die('连接失败');
$db->query('set names utf8');

//判断修改状态
if(!empty($_GET['id'])){
	$sno = $_GET['id'];
	$sql = "update student set status = 1 where sno = '$sno'";
	$res = $db->query($sql);
}


//查数据
$sql = "select * from student where status >= 0";
$res = $db->query($sql);
$arr = $res->fetch_all();




?>




<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>列表页</title>
<style>
	.spanErr{
		background: red;
		cursor: pointer;
	}
	.spanSu{
		background: green;
		cursor: pointer;
	}
	
</style>
</head>

<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
	<tr>
		<th>学号</th>
		<th>姓名</th>
		<th>性别</th>
		<th>生日</th>
		<th>班级</th>
		<th>操作</th>
	</tr>
<!--	循环添加数据-->
	<?php foreach($arr as $v) { ?>
		<tr>
			<td><?php echo $v[0]; ?></td>
			<td><?php echo $v[1]; ?></td>
			<td><?php echo $v[2]; ?></td>
			<td><?php echo $v[3]; ?></td>
			<td><?php echo $v[4]; ?></td>
			<td><?php echo $v[5]==0 ? "<a href='list.php?id=$v[0]'><span class='spanErr'>未审核</span></a>" : '<span class="spanSu">已通过</span>'; ?></td>
			<!-- a标签传值,把sno传过去,判断哪个的状态修改 -->
		</tr>
	<?php } ?>
	
	
</table>
</body>
</html>

  登录页

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>登录页</title>
</head>

<body>
<form action="php.php" method="post">
	账号: <input type="text" name="sname"><br>
	密码: <input type="text" name="sno"><br>
	<button>登录</button>
	<a href="zhuce.php">注册</a>
</form>
</body>
</html>

  注册页

<?php
if(!empty($sno)){
	//连接数据库
	$db = new MySQLi('localhost','root','','z_1032');
	!mysqli_connect_error() or die('连接失败');
	$db->query('set names utf8');
	
	
	//接收值
	$sno = $_POST['sno'];
	$sname = $_POST['sname'];
	$ssex = $_POST['ssex'];
	$sbirthday = $_POST['sbirthday'];
	$class = $_POST['class'];
	
	
	//执行sql
	$sql = "insert into student values ('$sno','$sname','$ssex','$sbirthday','$class',0)";
	$res = $db->query($sql);
	if($res){
		echo "注册成功";
	}else{
		echo "注册失败";
	}
	
}
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>注册页</title>
</head>

<body>
<form action="#" method="post">
	学号: <input type="text" name="sno"><br>
	姓名: <input type="text" name="sname"><br>
	性别: <input type="text" name="ssex"><br>
	生日: <input type="text" name="sbirthday"><br>
	班级: <input type="text" name="class"><br>
	<button>注册</button>
	<a href="list.php">查看用户列表</a>
</form>
</body>
</html>

  后台页

<?php
//连接数据库
$db = new MySQLi('localhost','root','','z_1032');
!mysqli_connect_error() or die('连接失败');
$db->query('set names utf8');

//接收数据
$sname = $_POST['sname'];//账号
$sno = $_POST['sno'];//密码


//查询 审核状态为通过或者是管理员
$sql = "select sno from student where sname = $sname and status != 0";
$res = $db->query($sql);
$arr = $res->fetch_row();  //结果集专数组, 结果是一维数组

//判断给出结果
if($sno != '' && $arr == ''){
	echo "账号密码错误或者未通过审核";
}else{
	echo "登录成功";
}
?>

  

猜你喜欢

转载自www.cnblogs.com/1500418882qqcom/p/10203265.html