-
Notifications
You must be signed in to change notification settings - Fork 1
/
Login.php
54 lines (54 loc) · 1.52 KB
/
Login.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
<?php
$username = $_POST['username'];
$Password = $_POST['Password'];
$isRegister = $_POST['Register'];
$con = mysql_connect("","schoolhunter_admin","admin123");
if (!$con){
die('Could not connect: ' . mysql_error());
}
// make schoolhunter_DataBase as the current db
$db_selected = mysql_select_db('schoolhunter_DataBase', $con);
if (!$db_selected) {
die ('Can\'t use schoolhunter_DataBase : ' . mysql_error());
}
// check register or login
if($isRegister){
$result = mysql_query("SELECT * FROM Users WHERE username ='".$username."'");
$row = mysql_fetch_array($result);
if($row){
echo "Username already registered";
}else{
mysql_query("INSERT INTO Users (username, password,school1,school2,school3,school4,school5,school6,school7,school8,isadmin) VALUES ('".$username."', '".$Password."', '0', '0', '0', '0', '0', '0','0','0','0')");
setcookie("username", $username, time() + 3600);
header('Location: main.php');
}
}else{
$result = mysql_query("SELECT * FROM Users WHERE username ='".$username."'AND Password ='".$Password."'");
$row = mysql_fetch_array($result);
if ($row){
setcookie("username", $username, time() + 3600);
if($row['isAdmin'] == 1){
header('Location: Admin.php');
}else{
//if(!isset($_COOKIE['username'])){
// if browser does not support cookie
// header('Location: welcome.php');
//} else {
header('Location: main.php');
//}
}
}else{
echo "Wrong username or password";
}
}
mysql_close($con);
?>
<html>
<head>
<title>
Main Page
</title>
</head>
<body>
</body>
</html>