不知道是什么错误
这是register.php
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>注册</title>
<link href="style/css/bootstrap.min.css" rel="stylesheet">
<link href="style/css/site.min.css" rel="stylesheet">
</head>
<body>
<!--导航栏-->
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand hidden-sm" href="index.html">慕课网</a>
</div>
</div>
</div>
<!--导航栏结束-->
<!-- 注册页面 -->
<div class="container projects">
<div class="projects-header page-header" id="register_head">
<h3>注册</h3>
</div>
<!--注册框-->
<div class="row" id="register_container">
<div class="col-md-6 col-md-offset-3">
<form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">姓名</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="请输入姓名">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">学号</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="请输入学号">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">邮箱</label>
<div class="col-sm-10">
<input type="email" class="form-control" placeholder="请输入正确邮箱">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">金钱</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="请输入数字">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">头像</label>
<div class="col-sm-10">
<input type="file">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">个人简介</label>
<div class="col-sm-10">
<textarea class="form-control" rows="2" placeholder="不超过50字"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary btn-default">提交</button>
<button type="submit" class="btn btn-default">重置</button>
</div>
</div>
</form>
</div>
</div>
<!--登录框-->
<!-- 登录页面 -->
<div class="projects-header page-header" style="display:none;" id="login_head">
<h3>登录</h3>
</div>
<!-- 登录框 -->
<div class="row" style="display:none" id="login_container">
<div class="col-md-6 col-md-offset-3">
<form class="form-horizontal" action="register.class.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">姓名</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="请输入姓名,字数不超过10位" name="name">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">学号</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="请输入学号,数字不超过8位" name="number">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary btn-default">提交</button>
<button type="reset" class="btn btn-default">重置</button>
</div>
</div>
</form>
</div>
</div>
</div>
<footer class="footer container">
<div class="row footer-bottom">
<ul class="list-inline text-center">
<h4><a href="http://class.imooc.com" target="_blank">class.imooc.com</a> | 慕课网</h4>
</ul>
</div>
</footer>
<script src="style/js/jquery.min.js"></script>
<script src="style/js/bootstrap.min.js"></script>
</body>
</html>
<?php
$action=$_REQUEST['action'];
switch($action){
case "register":
echo '<script>
document.getElementById("register_head").style.display="block";
document.getElementById("register_container").style.display="block";
document.getElementById("login_head").style.display="none";
document.getElementById("login_container").style.display="none";
</script>';
break;
case "login":
echo '<script>
document.getElementById("register_head").style.display="none";
document.getElementById("register_container").style.display="none";
document.getElementById("login_head").style.display="block";
document.getElementById("login_container").style.display="block";
</script>';
break;
}
?>
这是register.class.php
<?php
session_start();
$name = $_POST['name'];
$number = $_POST['number'];
$user = getUser();
$mark=getMark();
if($mark===false){
//登录失败
sendLoginFailedResponse();
};
$_SESSION['name']=$user[$mark][2];
header('index.php');
//查找用户,获得索引
function getMark(){
for($i=0;$i<100;$i++){ //之后要修改的
if( $user[$i][2]==$name && $user[$i][3]==$number ){
$mark=$i;
return $mark;
}
}
return false;
}
//echo '<pre>';
//foreach($user as $k=>$v){
// foreach ($v as $key=>$value){
// echo $key.':'.$value.'<br>';
// }
//};
//使用pdo获取数据库中的用户信息
function getUser(){
$dsn='mysql:host=localhost;dbname=imooc';
$pdo=new PDO($dsn,'root','root');
$pdo->exec('set names utf8');
$sql='select * from student_management';
$stmt=$pdo->query($sql);
$data=$stmt->fetchAll(PDO::FETCH_ASSOC);
return $data;
}
function sendLoginFailedResponse(){
$response="<script>
alert('姓名或学号错误');
window.location='index.php;
</script>";
echo $response;
die;
}
在register.php的登录页面时,输入姓名学号登录后为什么会出现下面这种状况
正在回答 回答被采纳积分+1
兄弟,可参考https://blog.csdn.net/al_assad/article/details/70510889 查看你是哪种情况
- 参与学习 人
- 提交作业 225 份
- 解答问题 3372 个
掌握用PHP开发互联网网站的必备功能,掌握当下主流的Linux系统开发,并熟练使用热门框架ThinkPhp开发电商团购项目,是通向PHP工程师必经之路。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星