php登录系统显示空白页面
我创建了6个php文件,它们是php登录系统显示空白页面,php,mysql,Php,Mysql,我创建了6个php文件,它们是teacher.php,student.php,login.php,logout.php,index.php,和config.php 我已经做了一些编码,它显示了: username: password 我可以输入我在数据库中注册的帐户名和密码 但在我输入我的帐户名和密码后,或者输入了错误的密码,或者什么都没有输入。只需按回车键 它显示空白页,但不显示任何内容 它的问题是,我错过了一些编码或任何错误 很抱歉,因为我是php新手,希望您能给我一些建议:) 我认为主要
teacher.php
,student.php
,login.php
,logout.php
,index.php
,和config.php
我已经做了一些编码,它显示了:
username:
password
我可以输入我在数据库中注册的帐户名和密码
但在我输入我的帐户名和密码后,或者输入了错误的密码,或者什么都没有输入。只需按回车键
它显示空白页,但不显示任何内容
它的问题是,我错过了一些编码或任何错误
很抱歉,因为我是php新手,希望您能给我一些建议:)
我认为主要问题在于login.php,代码如下:
<?php
include "config.php";
if(isset($_POST['log'])){
$user = $_POST['user'];
$pass = md5($_POST['pass']);
$hsl = mysql_query("select * from login where user='$user' and pass='$pass'");
$data = mysql_fetch_array($hsl);
$username = $data['user'];
$password = $data['pass'];
$type = $data['type'];
$name = $data['name'];
if($user==$username && $pass=$password){
session_start();
$_SESSION['name']=$name;
if($type=='student'){
echo "<script>location.assign('student.php')</script>";
}else if($type=='teacher'){
echo "<script>location.assign('teacher.php')</script>";
} else{
echo "<script>location.assign('wrong page.php')</script>";
}
}
}
?>
注意:
mysql在PHP5.5.0中被弃用,在PHP7.0.0中被删除。
相反,应该使用or扩展名
请尝试以下代码:-
// add this line always first
session_start();
include "config.php";
if(isset($_POST['log'])){
$user = $_POST['user'];
$pass = md5($_POST['pass']);
$hsl = mysql_query("select user,type,name from login where user='$user' and pass='$pass'");
if (!$hsl) {
// Debug query result by below code
//echo 'Could not run query: ' . mysql_error();
//exit;
echo '<script language="javascript">';
echo 'alert("Username / Password Seems Wrong !")';
echo '</script>';
}else{
$row = mysql_fetch_row($hsl);
$username = $row[0];
$type = $row[1];
$name = $row[2];
$_SESSION['name'] = $name;
if($type=='student'){
echo "<script>location.assign('student.php')</script>";
}else if($type=='teacher'){
echo "<script>location.assign('teacher.php')</script>";
} else{
echo "<script>location.assign('wrong page.php')</script>";
}
}
//始终首先添加此行
会话_start();
包括“config.php”;
如果(isset($_POST['log']){
$user=$_POST['user'];
$pass=md5($_POST['pass']);
$hsl=mysql_查询(“从登录名中选择用户、类型、名称,其中用户='$user'和pass='$pass'”);
如果(!$hsl){
//通过下面的代码调试查询结果
//echo“无法运行查询:”。mysql_错误();
//退出;
回声';
echo“警报(“用户名/密码似乎错误!”);
回声';
}否则{
$row=mysql\u fetch\u row($hsl);
$username=$row[0];
$type=$row[1];
$name=$row[2];
$\会话['name']=$name;
如果($type=='student'){
echo“location.assign('student.php')”;
}else if($type=='teacher'){
echo“location.assign('teacher.php')”;
}否则{
echo“location.assign('error page.php')”;
}
}
如果要重定向到文件,请按以下方式更改您的条件:-
if($type=='student'){
//echo "<script>location.assign('student.php')</script>";
header("Location: student.php");
}else if($type=='teacher'){
//echo "<script>location.assign('teacher.php')</script>";
header("Location: teacher.php");
} else{
//echo "<script>location.assign('wrong page.php')</script>";
header("Location: wrong page.php");
}
}
if($type=='student'){
//echo“location.assign('student.php')”;
标题(“位置:student.php”);
}else if($type=='teacher'){
//echo“location.assign('teacher.php')”;
标题(“位置:teacher.php”);
}否则{
//echo“location.assign('error page.php')”;
标题(“位置:错误的page.php”);
}
}
希望它能帮助您:)您需要了解有关错误报告的信息。您想重定向到student.php文件还是只想加载该文件的内容?谢谢您的建议!我试过了,它让我加载到一个,但在我输入了一个教师帐户和密码到列后,它仍然登录到,但没有请检查我的更新答案。