Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string user_id = "djfkjkj";
- string name = "dkjfls";
- string branch = "jd";
- string agency = "hhfh";
- string datastr = "{"user_id":"" + user_id + "","name":"" + name + "","branch": " + branch + "," + " "agency" : "" + agency + ""}";
- var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost/api/ucd.php");
- httpWebRequest.ContentType = "application/json";
- httpWebRequest.Method = "POST";
- using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
- {
- string json = JsonConvert.SerializeObject(datastr);
- streamWriter.Write(json);
- streamWriter.Flush();
- streamWriter.Close();
- }
- var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
- using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
- {
- var result = streamReader.ReadToEnd();
- }
- <?php
- header('Content-type: application/json');
- $conn = mysqli_connect("localhost", "users", "p*ssw2d", "dbdata");
- if($_SERVER['REQUEST_METHOD'] == "POST")
- {
- $r_data = file_get_contents("php://input");
- $user_id= $r_data ['user_id'];
- $user_name= $r_data ['name'];
- $branch= $r_data ['branch'];
- $agency= $r_data ['agency'];
- $sql = "INSERT INTO portal_users (pu_user_id, pu_username, pu_branch, pu_agency) VALUES ('" .$user_id."','".$user_name."','".$branch."','".$agency."');";
- $qur = $conn->query($sql);
- if($qur)
- {
- $json = array("status" => 1, "msg" => $user_id);
- }
- else
- {
- $json = array("status" => 0, "msg" => "Error adding user!");
- }
- }
- else
- {
- $json = array("status" => 0, "msg" => "Request method not accepted");
- }
- mysqli_close($conn);
- echo json_encode($json);
- ?>
- $r_val = file_get_contents("php://input");
- $r_data=json_decode($r_val, true);
- $user_id= $r_data ['user_id'];
- $user_name= $r_data ['name'];
- $branch= $r_data ['branch'];
- $agency= $r_data ['agency'];
- $r_data = file_get_contents("php://input");
- $user_id= $r_data ['user_id'];
- $r_json = file_get_contents("php://input");
- $r_data = json_decode($r_json, true);
- $user_id= $r_data ['user_id'];
- ...
- $conn = new PDO("mysql:host=localhost;dbname=dbdata", "users", "p*ssw2d");
- if($_SERVER['REQUEST_METHOD'] == "POST") {
- $r_json = file_get_contents("php://input");
- $r_data = json_decode($r_json, true);
- $user_id = $r_data['user_id'];
- $user_name = $r_data['name'];
- $branch = $r_data['branch'];
- $agency = $r_data['agency'];
- $sql = "INSERT INTO portal_users (pu_user_id, pu_username, pu_branch, pu_agency) VALUES (?, ?, ?, ?);";
- $stmt = $conn->prepare($sql);
- $qur = $stmt->execute([$user_id, $user_name, $branch, $agency]);
- $json = $qur ? ["status"=>1, "msg"=>$user_id] : ["status"=>0, "msg"=>"Error adding user!"];
- } else {
- $json = ["status"=>0, "msg"=>"Request method not accepted"];
- }
- header("Content-type: application/json");
- echo json_encode($json);
Add Comment
Please, Sign In to add comment