-
Notifications
You must be signed in to change notification settings - Fork 0
/
loginaction.php
53 lines (48 loc) · 1.52 KB
/
loginaction.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
52
53
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "projectindra";
$uname = test_input($_POST["Username"]);
$pass = test_input($_POST["passwd"]);
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$pass=md5($pass);
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM users WHERE (Uname='$uname'OR Email = '$uname') AND Password = '$pass'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$uname=$row["Uname"];
$fname=$row["Fname"];
$email=$row["Email"];
$_SESSION['uname']=$uname;
$_SESSION['fname']=$fname;
$_SESSION['email']=$email;
$_SESSION['logged_in']='Active';
header('location: indra.php');
}
} else {
/*echo "<html>";
echo "<script src='https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js'></script>";
echo "<body>";
echo "<script>swal('Username or password is incorrect','','warning')</script>";
echo "</body>";
echo "</html>";*/
$_SESSION['uname']=$uname;
$_SESSION['error'] = 'Incorrect Username or Password';
header('location: index.php');
}
mysqli_close($conn);
?>