-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
76 lines (62 loc) · 2.31 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
<?php
session_start();
$link=mysqli_connect("localhost","root","","pocketmanager");
if(mysqli_connect_error()){
die("Connection Failed");
}
$query="";
$result="";
if($_POST){
$type=$_POST["sg"];
if($type=="userSignup"){
$mail=$_POST["semail"];
$fname=$_POST["fname"];
$pass=$_POST["spassword"];
$lname=$_POST["lname"];
$query="select * from users where email='".mysqli_real_escape_string($link,$mail)."'";
if(!mysqli_query($link,$query)){
echo "Failure";
}
else{
$result=mysqli_query($link,$query);
if(mysqli_num_rows($result)==0){
$query="insert into users(fname,lname,email,password) values('$fname','$lname','$mail','$pass')";
if($result=mysqli_query($link,$query)){
$_SESSION['userName']=$fname;
//echo"Account Created";
header("Location: indeX_.php?accCreatedSuccessfull");
}
else{
//echo"Account not Created";
header("Location: indeX_.php?accCreationFailed");
}
}
else{
//echo "User already present";
header("Location: indeX_.php?accCreationFailed");
}
}
}
else if($type=="userLogin"){
$mail=$_POST["lemail"];
$pass=$_POST["lpassword"];
$query="select * from users where email='".mysqli_real_escape_string($link,$mail)."' and password='".$pass."' limit 1";
$result=mysqli_query($link,$query);
// print_r("Result:".$result);
if (!$result) {
echo("Error: %s\n");
exit();
}
//echo mysqli_num_rows($result);
$row=mysqli_fetch_array($result);
$userName=$row['fname'];
if(!$userName){
echo "Failure";
}
else{
$_SESSION['userName']=$userName;
header("Location: indeX_.php?".$userName);
}
}
}
?>