-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
54 lines (38 loc) · 1.78 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
<?php
//bring in SQLcon.php file
require_once 'SQLcon.php';
//check if the POST request method has been used
if($_SERVER["REQUEST_METHOD"] == 'POST' ){
if(!empty($_POST['user']) && !empty($_POST['password'])){
//create vraibles named $user and $password, set them equal to whats stored in the POST array 'user' and 'password' elements.
$user = $_POST['user'];
$password = $_POST['password'];
//create a variable called $loginQuery and use it to store an SQL query
$loginQuery = " SELECT user, password
FROM users
WHERE user = '$user'
AND password = '$password'";
//run the query using mysqli_query method, passing it the database connection and query as parameters.store the results in a variable
$loginResult = mysqli_query($con,$loginQuery);
//use mysqli_num_rows method to determine if $loginResult contains anything, if it does set $_SESSION array with user info and rediredct to list.php else redirect back to this page.
if(mysqli_num_rows($loginResult)>0){
echo "right";
$_SESSION['user'] = $user;
$_SESSION['password'] = $password;
header("Location:list.php");
die();
}
else{
echo "wrong";
echo mysqli_error_list($con);
echo mysqli_error($con);
header('Location:loginIndex.php');
echo "Failed to login";
die();
}
}
else{
header("Location:loginIndex.php");
}
}
?>