-
Notifications
You must be signed in to change notification settings - Fork 0
/
signin.php
67 lines (54 loc) · 1.97 KB
/
signin.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
67
<?php include 'dbconnect.php' ?>
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<head>
<title>Smart Customer Services</title>
<link rel="stylesheet" href="project-team19.css">
</head>
<body>
<div class="menu-bar">
<div>
<a href="signup.php">Sign Up</a>
</div>
<div>
<a href="signin.php">Sign In</a>
</div>
</div>
<form id="signup" action="" method="post">
<div id="signInField">
<h2>Already have an account? Sign in here.</h2>
<label>Log In Id:</label> <input type="text" name="login_id" required><br>
<label>Password:</label> <input type="password" name="password" required><br>
<input type="submit" name="signUp" value="Log in">
</div>
</form>
</body>
</html>
<?php
session_start();
require __DIR__ . './functions.php';
if (isset($_POST['signUp'])) {
$login_id = validate($_POST['login_id']);
$password = validate($_POST['password']);
$sql = "SELECT * FROM users WHERE login_id='$login_id' AND password='$password'";
$result = mysqli_query($connect, $sql);
if (mysqli_num_rows($result) === 1) {
while ($row = $result -> fetch_assoc()) {
if (!isset($_SESSION['login_id']) && !isset($_SESSION['password'])) {
$_SESSION['login_id'] = $row['login_id'];
$_SESSION['password'] = $row['password'];
$_SESSION['address'] = $row['address'];
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['cart_id'] = 1;
redirect("index.php");
}
}
}
else {
echo "<br>" . "Your ID or password is incorrect.";
}
$sql = "SELECT login_id, password FROM users";
$result = mysqli_query($connect, $sql);
}
?>