-
Notifications
You must be signed in to change notification settings - Fork 0
/
login_check.php
69 lines (45 loc) · 1.63 KB
/
login_check.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.1/css/toastr.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.1/js/toastr.js"></script>
</head>
<body>
<?php
error_reporting(0);
session_start();
$host = "localhost";
$user = "root";
$password = "";
$db = "schooldb";
$data = mysqli_connect($host, $user, $password, $db);
if($data===false){
die("Connection Error!!");
}
if(isset($_POST['submit'])){
$name = $_POST['username'];
$pass = $_POST['password'];
$sql = "SELECT * from users where username='".$name."' AND password='".$pass."' ";
$result = mysqli_query($data, $sql);
$row = mysqli_fetch_array($result);
if($row["usertype"]=="student"){
$_SESSION['username']=$name;
$_SESSION['usertype']="student";
header("location:student_home.php");
}elseif($row["usertype"]=="teacher"){
$_SESSION['username']=$name;
$_SESSION['usertype']="teacher";
header("location:teacher_home.php");
} elseif($row["usertype"]=="admin") {
$_SESSION['username']=$name;
$_SESSION['usertype']="admin";
header("location:admin.php");
} else {
$message = "Invalid username or password";
$_SESSION['loginMessage']=$message;
header("location:login.php");
}
}
?>
</body>
</html>