-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemp_check.php
47 lines (45 loc) · 2.08 KB
/
emp_check.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
<?php
session_start();
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
mysql_connect("localhost", "root","") or die(mysql_error()); //Connect to server
mysql_select_db("dbms") or die("Cannot connect to database"); //Connect to database
$query = mysql_query("SELECT * from employee WHERE username='$username'"); //Query the users table if there are matching rows equal to $username
$exists = mysql_num_rows($query); //Checks if username exists
$table_users = "";
$table_password = "";
if($exists > 0) //IF there are no returning rows or no existing username
{
while($row = mysql_fetch_assoc($query)) //display all rows from query
{
$table_users = $row['username']; // the first username row is passed on to $table_users, and so on until the query is finished
$table_password = $row['password']; // the first password row is passed on to $table_users, and so on until the query is finished
}
if(("admin" == $table_users) && ("admin" == $table_password)) // checks if there are any matching fields
{
if($password == $table_password)
{
$_SESSION['employee'] = $username; //set the username in a session. This serves as a global variable
header("location: admin.php"); // redirects the user to the authenticated home page
}
}
elseif(($username == $table_users) && ($password == $table_password)) // checks if there are any matching fields
{
if($password == $table_password)
{
$_SESSION['employee'] = $username; //set the username in a session. This serves as a global variable
header("location: home1.php"); // redirects the user to the authenticated home page
}
}
else
{
Print '<script>alert("Incorrect Password!");</script>'; //Prompts the user
Print '<script>window.location.assign("emplog.php");</script>'; // redirects to login.php
}
}
else
{
Print '<script>alert("Incorrect Username!");</script>'; //Prompts the user
Print '<script>window.location.assign("emplog.php");</script>'; // redirects to login.php
}
?>