-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
executable file
·80 lines (71 loc) · 2.07 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!-/* changed mysql to mysqli -------------- */->
<!doctype html>
<html>
<head>
<title>LoginForm</title>
<style>
body{
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
background-color: azure ;
color: palevioletred;
font-family: verdana;
font-size: 100%
}
h1 {
color: indigo;
font-family: verdana;
font-size: 100%;
}
h3 {
color: indigo;
font-family: verdana;
font-size: 100%;
} </style>
</head>
<body>
<center><h1>CREATE REGISTRATION AND LOGIN FORM USING PHP AND MYSQL</h1></center>
<p><a href="register.php">Register</a> | <a href="login.php">Login</a></p>
<h3>Login Form</h3>
<form action="" method="POST">
Username: <input type="text" name="user"><br />
Password: <input type="password" name="pass"><br />
<input type="submit" value="Login" name="submit" />
</form>
<?php
if(isset($_POST["submit"])){
if(!empty($_POST['user']) && !empty($_POST['pass']))
echo "ho";
if(!empty($_POST['user']) && !empty($_POST['pass'])) {
$user=$_POST['user'];
$pass=$_POST['pass'];
$con=mysqli_connect('localhost','root','') or die(mysqli_error());
mysqli_select_db($con,'alphacrm') or die(mysqli_error($con));
$query=mysqli_query($con,"SELECT * FROM login WHERE username='".$user."' AND password='".$pass."'");
$numrows=mysqli_num_rows($query);
if($numrows!=0)
{
while($row=mysqli_fetch_assoc($query))
{
$dbusername=$row['username'];
$dbpassword=$row['password'];
}
if($user == $dbusername && $pass == $dbpassword)
{
session_start();
$_SESSION['sess_user']=$user;
/* Redirect browser */
header("Location: member.php");
}
} else {
echo "Invalid username or password!";
}
} else {
echo "All fields are required!";
}
}
?>
</body>
</html>