-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
138 lines (120 loc) · 5.4 KB
/
index.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<?php
include 'db.php';
// session_start();
if (isset($_POST['login'])) {
$user = mysqli_real_escape_string($conn, $_POST['userid']);
$pass = mysqli_real_escape_string($conn, $_POST['pass']);
$_SESSION['user'] = $user;
$sql = "SELECT * FROM user WHERE username = '$user' AND password = '$pass' AND status = 'ACTIVE'";
$result = $conn->query($sql) or die(mysqli_error());
if (mysqli_num_rows($result)) {
$_SESSION['user'] = $user;
while ($row = $result->fetch_assoc()) {
if ($row['role'] == 'STUDENT' and $row['status'] == 'ACTIVE') {
echo "<script>
alert('Login Successful " .$user. "');
window.location.href = 'studentprofile.php';
</script>";
}
if ($row['role'] == 'TEACHER' and $row['status'] == 'ACTIVE') {
echo "<script>
alert('Login Successful');
window.location.href = 'teacherprofile.php';
</script>";
}
if ($row['role'] == 'ADMIN') {
echo "<script>
alert('Login Successful');
window.location.href = 'userManagement.php';
</script>";
}
}
} else {
echo "<script>
alert('Incorrect Username or Password!');
window.location.href = 'index.php';
</script>";
}
}
if (isset($_POST['register'])) {
$newuser = mysqli_real_escape_string($conn, $_POST['newuser']);
$newpass = mysqli_real_escape_string($conn, $_POST['newpass']);
$conpass = mysqli_real_escape_string($conn, $_POST['confirmpass']);
$role = $_POST['role'];
$sql = "SELECT * FROM user WHERE username = '$newuser'";
$result = $conn->query($sql) or die(mysqli_error());
if (mysqli_num_rows($result)) {
echo "<script>
alert('Username already registered!');
window.location.href = 'index.php';
</script>";
} else {
if ($newpass == $conpass and $newuser != '' and $newpass != '') {
$_SESSION['user'] = $newuser;
$sqlinsert = "INSERT INTO user (username, password, role, status) VALUES ('$newuser', '$newpass', '$role', 'ACTIVE');";
$result = $conn->query($sqlinsert) or trigger_error("Query Failed! SQL: $sqlinsert - Error: " . mysqli_error(), E_USER_ERROR);
if ($role == 'STUDENT') {
echo "<script>window.location.href = 'studentprofile.php';</script>";
} else {
echo "<script>window.location.href = 'teacherprofile.php';</script>";
}
} else {
echo "<script>
alert('Password do not match or some fields are blank!');
window.location.href = 'index.php';
</script>";
}
}
}
?>
<html>
<head>
<title>Essay Checker</title>
<link rel="stylesheet" type="text/css" href="css/maindesign.css" />
</head>
<body background="bg.jpg">
<div id="container">
<div id="header">
<form method="POST" action="#">
<label style="top: 5px; left: 15px; font-size: 30px; position: absolute;">Vanguard Essay Checker</label>
<div id="login">
<img src="img/user.png" id="iconimage" />
<input type="text" name="userid" placeholder="Username" maxlength="50" />
<img src="img/padlock.png" id="iconimage" style="left: 215px;" />
<input type="password" name="pass" maxlength="50" placeholder="Password" />
<input type="submit" value="Login" name="login" class="success" />
</div>
</form>
</div>
<fieldset id="infodiv">
<label style="font-size: 30px;">Welcome to Vanguard <br />Essay Checker</label>
<br /><br />
<label>the best place to connect teacher and student thoughts</label>
<br />
</fieldset>
<fieldset id="register">
<form method="POST" action="#">
<label>Easy and Fast Registration</label>
<br /><br />
<label>Username</label>
<br />
<input type="text" name="newuser" maxlength="50" placeholder="Username" style="width: 250px; padding: 5px;" />
<br /><br />
<label>Password</label>
<br />
<input type="password" name="newpass" maxlength="50" placeholder="Password" style="width: 250px; padding: 5px;" />
<br /><br />
<label>Confirm Password</label>
<br />
<input type="password" name="confirmpass" maxlength="50" placeholder="Confirm Password" style="width: 250px; padding: 5px;" />
<br /><br />
<input type="radio" name="role" value="STUDENT" checked />I'm a Student
<input type="radio" name="role" value="TEACHER" />I'm a Teacher
<br /><br />
<input type="submit" value="Register" name="register" class="reg" />
</form>
</fieldset>
</div>
</body>
</html>