-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
90 lines (81 loc) · 2.22 KB
/
api.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
81
82
83
84
85
86
87
88
89
90
<?php
require_once('connection.inc.php');
$req=$_SERVER['REQUEST_METHOD'];
if($req=='POST'){
if(isset($_POST['action'])){
if($_POST['action']=='register'){
$result=mysqli_query($connection,"SELECT `mobile` FROM `app`.`users` WHERE `mobile`='{$_POST['mobile']}'");
$row_cnt = mysqli_num_rows($result);
if($row_cnt>0)
{
$error=1;
$message="This mobile number is already registered!!";
return $message;
}
else{
$password=md5($_POST['pass']);
$sql="INSERT INTO `app`.`users`(`name`,`mobile`,`gender`,`password`)VALUES('{$_POST['name']}','{$_POST['mobile']}','{$_POST['gender']}','$password')";
mysqli_query($connection,$sql);
}
}
elseif($_POST['action']=='login'){
$result=mysqli_query($connection,"SELECT `password`,`name` FROM `app`.`users` WHERE `mobile`='{$_POST['mobile']}'");
$row_cnt = mysqli_num_rows($result);
if($row_cnt>0)
{
$login=mysqli_fetch_assoc($result);
$login_pass=$login['password'];
$login_name=$login['name'];
if($login_pass==md5($_POST['pass'])){
$_SESSION['name']=$login_name;
return true;
}
else{
$error=1;
$message="Password and email address combination does not match!!";
return $message;
}
}
else
{
$error=1;
$message="Entered email address is not registered!!";
return $message;
}
}
elseif($_POST['action']=='alert'){
$type=$_POST['type'];
$result=mysqli_query($connection,"SELECT `password`,`name` FROM `app`.`users` WHERE `mobile`='{$_POST['mobile']}'");
$row_cnt = mysqli_num_rows($result);
if($row_cnt>0)
{
$user=mysqli_fetch_assoc($result);
}
if($type=="road-accident"){
$amb=1;
$pol=1;
$data = array( $user,$amb,$pol,$fb);
}
elseif($type=="earthquake"){
$amb=1;
$data = array( $user,$amb,$pol,$fb);
}
elseif($type=="fire"){
$amb=1;
$pol=1;
$fb=1;
$data = array( $user,$amb,$pol,$fb);
}
$sql1="INSERT INTO `app`.`alert`(`name`,`mobile`,`type`)VALUES('{$_POST['name']}','{$_POST['mobile']}','$type')";
mysqli_query($connection,$sql1);
}
}
else
{
die("require action");
}
}elseif($req=='GET')
{
}
echo json_encode( $data);
?>