-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdatabase6.php
30 lines (30 loc) · 1.08 KB
/
database6.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
<?php
// Login to user : needs to have a user table in the database
session_start();
include 'db.php';
//If logged in then redirect
if(isset($_SESSION['login_user']))
header('Location: '.LOGIN_SUCCESS);
//Execute on form submission
if($_SERVER["REQUEST_METHOD"] == "POST") {
//SANITIZE input fields here
$username = mysqli_real_escape_string($db_con,$_POST['email']);
$password = mysqli_real_escape_string($db_con,$_POST['password']);
//Query to execute
$sql = "SELECT id FROM " . DB_USERTABLE . " WHERE username = '$username' and password = '$password'";
$result = mysqli_query($db_con,$sql);
//Uncomment code below for debugging
// if(!$result)
// echo("Error description: " . mysqli_error($db_con));
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
// If result matched $username and $password, table row count must be 1
if($count == 1) {
//Login successful
$_SESSION['login_user'] = $username;
header("location: ".LOGIN_SUCCESS);
}else {
$error = "Your Login email or Password is invalid";
}
}
?>