Guest User

Untitled

a guest
Dec 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. string user_id = "djfkjkj";
  2. string name = "dkjfls";
  3. string branch = "jd";
  4. string agency = "hhfh";
  5.  
  6. string datastr = "{"user_id":"" + user_id + "","name":"" + name + "","branch": " + branch + "," + " "agency" : "" + agency + ""}";
  7.  
  8. var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost/api/ucd.php");
  9. httpWebRequest.ContentType = "application/json";
  10.  
  11. httpWebRequest.Method = "POST";
  12.  
  13. using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
  14. {
  15. string json = JsonConvert.SerializeObject(datastr);
  16.  
  17. streamWriter.Write(json);
  18. streamWriter.Flush();
  19. streamWriter.Close();
  20. }
  21.  
  22. var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  23. using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
  24. {
  25. var result = streamReader.ReadToEnd();
  26. }
  27.  
  28. <?php
  29. header('Content-type: application/json');
  30.  
  31. $conn = mysqli_connect("localhost", "users", "p*ssw2d", "dbdata");
  32. if($_SERVER['REQUEST_METHOD'] == "POST")
  33. {
  34. $r_data = file_get_contents("php://input");
  35. $user_id= $r_data ['user_id'];
  36. $user_name= $r_data ['name'];
  37. $branch= $r_data ['branch'];
  38. $agency= $r_data ['agency'];
  39. $sql = "INSERT INTO portal_users (pu_user_id, pu_username, pu_branch, pu_agency) VALUES ('" .$user_id."','".$user_name."','".$branch."','".$agency."');";
  40. $qur = $conn->query($sql);
  41. if($qur)
  42. {
  43. $json = array("status" => 1, "msg" => $user_id);
  44. }
  45. else
  46. {
  47. $json = array("status" => 0, "msg" => "Error adding user!");
  48. }
  49. }
  50. else
  51. {
  52. $json = array("status" => 0, "msg" => "Request method not accepted");
  53. }
  54.  
  55. mysqli_close($conn);
  56. echo json_encode($json);
  57. ?>
  58.  
  59. $r_val = file_get_contents("php://input");
  60. $r_data=json_decode($r_val, true);
  61. $user_id= $r_data ['user_id'];
  62. $user_name= $r_data ['name'];
  63. $branch= $r_data ['branch'];
  64. $agency= $r_data ['agency'];
  65.  
  66. $r_data = file_get_contents("php://input");
  67.  
  68. $user_id= $r_data ['user_id'];
  69.  
  70. $r_json = file_get_contents("php://input");
  71. $r_data = json_decode($r_json, true);
  72. $user_id= $r_data ['user_id'];
  73. ...
  74.  
  75. $conn = new PDO("mysql:host=localhost;dbname=dbdata", "users", "p*ssw2d");
  76.  
  77. if($_SERVER['REQUEST_METHOD'] == "POST") {
  78. $r_json = file_get_contents("php://input");
  79. $r_data = json_decode($r_json, true);
  80. $user_id = $r_data['user_id'];
  81. $user_name = $r_data['name'];
  82. $branch = $r_data['branch'];
  83. $agency = $r_data['agency'];
  84. $sql = "INSERT INTO portal_users (pu_user_id, pu_username, pu_branch, pu_agency) VALUES (?, ?, ?, ?);";
  85. $stmt = $conn->prepare($sql);
  86. $qur = $stmt->execute([$user_id, $user_name, $branch, $agency]);
  87. $json = $qur ? ["status"=>1, "msg"=>$user_id] : ["status"=>0, "msg"=>"Error adding user!"];
  88. } else {
  89. $json = ["status"=>0, "msg"=>"Request method not accepted"];
  90. }
  91.  
  92. header("Content-type: application/json");
  93. echo json_encode($json);
Add Comment
Please, Sign In to add comment