-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
38 lines (35 loc) · 1.23 KB
/
index.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
<?php
session_start();
include_once "config/config.php";
include_once "uploadData.php";
$db = new Database();
$login = false;
if (isset($_POST['login'])) {
$email = $db->escapeString($_POST['email']);
$password = $db->escapeString($_POST['pass']);
$login = true;
// login validation
$errors = array();
// Check if email address do not exit
$result = $db->fetchUserInfo($email);
$num_of_rows = $result->num_rows;
if($num_of_rows == 0){
array_push($errors,"Email address do not exit!");
}else {
// put result into associative array
$row = $result->fetch_assoc();
// check if password match email address
if ($password !== $row["password"]) {
array_push($errors,"Incorrect password!");
}
}
// login user if no error
$errors_length = count($errors);
if ($errors_length < 1) {
// storing user information to be used in home page.
$db->storeUserInfo($row["username"],$row["email"]);
header("location:templates/userPage.php");
}
}
include_once "templates/login.php";
?>