-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
66 lines (52 loc) · 1.92 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
61
62
63
64
65
66
<?php
include('connecttodb.php');
$sql = 'SELECT name, email, password from users ';
$result = mysqli_query($conn, $sql);
$users = mysqli_fetch_all($result, MYSQLI_ASSOC); #stores the results in the form of an array
mysqli_free_result($result);
mysqli_close($conn);
$err='';
if (isset($_POST['submit'])) {
$email = htmlspecialchars($_POST['user_email']); #getting all data entered using form
$password = htmlspecialchars($_POST['user_password']);
foreach ($users as $user){ #validating if such an user exist in db using the array
if (htmlspecialchars($user['email'] == $email)) {
if (htmlspecialchars($user['password'] == $password)) {
$name = $user['name'];
header("Location: home.php?user=".$name);
}
else{
$err = "Invalid credentials";
}
}
else{
$err = "Invalid credentials";
}
}
}
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Form</title>
<link rel="stylesheet" href="login.css">
<link href='https://fonts.googleapis.com/css?family=Nunito:400,300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="login.css">
</head>
<body>
<form action="login.php" method="post" id="fo" name="fo" >
<h1>Login</h1>
<fieldset>
<label for="mail">Email:</label>
<input type="email" id="mail" name="user_email" required>
<label for="password">Password:</label>
<input type="password" id="password" name="user_password" required>
<div class="red"><?php echo $err;?></div> <!--printing error message-->
</fieldset>
<button type="submit" name="submit">Login</button>
or sign up
<a href="signup.php" >here</a>
</form>
</body>
</html>