-
Notifications
You must be signed in to change notification settings - Fork 3
/
ALogin.php
47 lines (41 loc) · 1.54 KB
/
ALogin.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(); // Starting Session
$error=''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
echo '<script language="javascript">';
echo 'alert("Username or Password is invalid");';
echo 'window.location.href = "AdminLogin.php";';
echo '</script>';
}
else
{
// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("localhost", "root", "","election");
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// Selecting Database
$db = mysql_select_db("election", $connection);
// SQL query to fetch information of registerd users and finds user match.
$query = mysql_query("select username , password from admin where password='$password' AND username='$username'", $connection);
$rows = mysql_num_rows($query);
if ($rows == 1) {
$_SESSION['login_user']=$username; // Initializing Session
header("location:AdminHome.php"); // Redirecting To Other Page
}
elseif(($_POST['username'] !=='username') ||($_POST['password'] !== 'password')){
echo '<script language="javascript">';
echo 'alert("Username or Password is invalid");';
echo 'window.location.href = "AdminLogin.php";';
echo '</script>';
}
mysql_close($connection); // Closing Connection
}
}
?>