-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
118 lines (99 loc) · 2.55 KB
/
Copy pathindex.php
File metadata and controls
118 lines (99 loc) · 2.55 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>LOGIN</title>
<link rel="stylesheet" type="text/css" href="">
<style type="text/css">
:root
{
--bgcolor-1: #150734;
--bgcolor-2: #0F2557;
--maincolor: #000000;
--btncolor: #0f2557;
}
.login1{
width: 500px;
border: 2px solid #ccc;
margin: 150px auto;
padding: 30px;
border-radius: 15px;
align-content: center;
}
h1{
text-align: center;
font-family: Comic Sans MS;
}
h2{
font-family: Comic Sans MS;
text-align: center;
margin-bottom: 40px;
}
label{
margin-left: 10px;
}
label, input {
display: block;
margin-bottom: 20px;
margin-left: 165px;
}
input[type="submit"] {
background-color: #0f2557;
color: white;
border: none;
padding: 10px 10px;
border-radius: 5px;
cursor: pointer;
display: block;
border: 2px solid #ccc;
width: 30%;
margin: 10px auto;
}
</style>
</head>
<body>
<h1>Welcome To Government Polytechnic Ratnagiri</h1>
<div class="login1">
<h2>USER LOGIN</h2>
<form method="post" action="">
<label>Username:</label>
<input type="text" name="username" required>
<label>Password:</label>
<input type="password" name="password" required>
<input type="submit" value="LOGIN " onclick="">
</form>
</div>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "cpp";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Validate user input
if (isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
// Check if username and password match database
$query = "SELECT * FROM login WHERE username='$username' AND password='$password'";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) == 1) {
// Redirect to protected page
header("Location: dashboard.php");
//exit();
} else {
// Login unsuccessful, display error message
echo '<script>';
echo 'alert("Invalid username or password.");';
echo '</script>';
}
}
mysqli_close($conn);
?>
</body>
</html>