forked from sawepeter/Angularjs-user-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddremove.php
42 lines (30 loc) · 1.14 KB
/
addremove.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
<?php
include 'config.php';
$data = json_decode(file_get_contents("php://input"));
$request_type = $data->request_type;
// Get all records
if($request_type == 1){
$sel = mysqli_query($con,"select * from users");
$data = array();
while ($row = mysqli_fetch_array($sel)) {
$data[] = array("id"=>$row['id'],"fname"=>$row['fname'],"lname"=>$row['lname'],"username"=>$row['username'],"password"=>$row['password']);
}
echo json_encode($data);
}
// Insert record
if($request_type == 2){
$fname = $data->fname;
$lname = $data->lname;
$uname = $data->uname;
$pass = $data->pass;
mysqli_query($con,"insert into users(fname,lname,username,password) values('".$fname."','".$lname."','".$uname."','".$pass."')");
$lastinsert_id = mysqli_insert_id($con);
$return_arr[] = array("id"=>$lastinsert_id,"fname"=>$fname,"lname"=>$lname,"username"=>$uname,"password"=>$pass);
echo json_encode($return_arr);
}
// Delete record
if($request_type == 3){
$userid = $data->userid;
mysqli_query($con,"delete from users where id=".$userid);
echo 1;
}