mysql - php login system shows out blank page -


this question has answer here:

i have create 6 php files teacher.php, student.php, login.php, logout.php, index.php, , config.php

i have done coding , shows out the:

username: password 

i input account name , password have registered in database.

but after input account name , password or wrong password or input nothing. press enter

it shows blank page show nothing.

what's wrong it, miss coding or error?

sorry because new on php , hope give me suggestion :)

as think main problem in login.php , these code:

<?php include "config.php"; if(isset($_post['log'])){        $user = $_post['user'];     $pass = md5($_post['pass']);     $hsl = mysql_query("select * login user='$user' , 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>";             }     } } ?> 

note:-

mysql_* deprecated in php 5.5.0, , removed in php 7.0.0. instead, mysqli or pdo_mysql extension should used.

try code:-

// add line first session_start(); include "config.php"; if(isset($_post['log'])){        $user = $_post['user'];     $pass = md5($_post['pass']);     $hsl = mysql_query("select user,type,name login user='$user' , pass='$pass'");      if (!$hsl) {         // debug query result 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 want redirect file change condition below:-

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

hope :)


Comments