forked from afzafri/Database-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
94 lines (72 loc) · 1.89 KB
/
Copy pathindex.php
File metadata and controls
94 lines (72 loc) · 1.89 KB
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
<?php
//Start session
session_start();
//Unset the variables stored in session
unset($_SESSION['SESS_MEMBER_ID']);
unset($_SESSION['SESS_MEMBER_USER']);
unset($_SESSION['SESS_MEMBER_PASS']);
?>
<html>
<head>
<link rel="shortcut icon" href="./images/dblogo.ico" />
<title>Database System</title>
<link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="./css/login.css">
</head>
<body>
<div class="logo"></div>
<div class="login-block">
<form action="index.php" method="post">
<h1>Login</h1>
<input type="text" value="" placeholder="Username" id="username" name="user"/>
<input type="password" value="" placeholder="Password" id="password" name="pass" />
<button>Submit</button>
</form>
</div>
<?php
$user = (isset($_POST["user"]) ? $_POST["user"] : null);
$pass = (isset($_POST["pass"]) ? $_POST["pass"] : null);
include 'config.php';
if(isset($_POST["user"]) && isset($_POST["pass"]))
{
try
{
//connect to db
$conn = new PDO("mysql:host=$servername;dbname=$dbname" , $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//sql query
$stmt = $conn->prepare("SELECT ID, USERNAME, PASSWORD FROM LOGIN");
//execute query
$stmt->execute();
//fetch
$result = $stmt->fetch(PDO::FETCH_ASSOC);
//store fetched data into variable
$i = $result['ID'];
$u = $result['USERNAME'];
$p = $result['PASSWORD'];
if($user == $u && $pass == $p)
{
session_regenerate_id();
$_SESSION['SESS_MEMBER_ID'] = $i;
$_SESSION['SESS_MEMBER_USER'] = $u;
$_SESSION['SESS_MEMBER_PASS'] = $p;
session_write_close();
header("location: home.php");
exit();
}
else
{
session_write_close();
header("location: index.php");
exit();
}
}
catch(PDOException $e)
{
echo "Connection failed : " . $e->getMessage();
}
$conn = null;
}
?>
</body>
</html>