-
Notifications
You must be signed in to change notification settings - Fork 2
/
login.php
60 lines (50 loc) · 1.49 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
55
56
57
58
59
60
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Index</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body style = "padding:10px;">
<br>
<div style='padding:20px'>
<h2>Login</h2>
<form action="login.php" method="post">
<input type="text" name="name" placeholder="Name" value="">
<input type="password" name="password" placeholder="Password" value="">
<input type="submit" name="submit" value="Login">
</form>
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = 'test';
$conn = mysqli_connect($servername, $username, $password, $dbname);
if($conn){
if(isset($_POST["submit"])){
$givenuser = $_POST["name"];
$givenpassword = $_POST["password"];
$res = mysqli_query($conn, "SELECT *
FROM User
WHERE username='$givenuser'
");
if(mysqli_num_rows($res)){
$x = mysqli_fetch_all($res);
$dbuser = $x[0][0];
$dbpassword = $x[0][1];
if($givenpassword==$dbpassword){
header('Location:index.php');
}
else{
echo "<h2>Wrong password</h2>";
}
}
else{
echo "<h2>Username doesn't exist in database</h2>";
}
}
}
echo "</div>";
echo "</body>";
echo "</html>";
?>