php登录系统显示空白页

标签 php mysql

我创建了 6 个 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_* was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.

试试这个代码:-

// 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>";
            }
    } 

如果您想重定向到文件,请更改您的条件,如下所示:-

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");
            }
    }

希望对你有帮助:)

关于php登录系统显示空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35080115/

相关文章:

php - 从 mysql 迁移到 PDO,不连接到 mysql 服务器

php - 在重载和变慢之前,AJAX 聊天能够在专用服务器上处理多少成员?

php - 需要有关 PREPARE sql 函数 PDO 的帮助

php - 注册 php 在尝试注册时一直出现连接重置错误

php - libsodium "Call to undefined function"错误

php - 带有提交按钮的复选框不起作用

mysql - 使用group by查询两个db并显示详细信息

mysql - Mac OS X 10.6、Mysql、Mysql-Python、Django

php - 确定 PHP 下周

php - 如何强制浏览器缓存文本文件 (.ttf)