Created
November 9, 2018 21:44
-
-
Save hquach/1c2a53682f99f1f39211feadc8731a84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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']); | |
} | |
echo json_encode($data); | |
} | |
// Insert record | |
if($request_type == 2){ | |
$fname = $data->fname; | |
$lname = $data->lname; | |
$username = $data->username; | |
mysqli_query($con,"insert into users(fname,lname,username) values('".$fname."','".$lname."','".$username."')"); | |
$lastinsert_id = mysqli_insert_id($con); | |
$return_arr[] = array("id"=>$lastinsert_id,"fname"=>$fname,"lname"=>$lname,"username"=>$username); | |
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; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment