Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2016
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
  2.  
  3. @IBAction func userSaveInfoButtonTapped(sender: AnyObject) {
  4. let userName = userNameTextField.text!
  5. let userAge = userAgeTextField.text!
  6. let userPhone = userPhoneTextFIeld.text!
  7. let userEmail = userEmailTextField.text!
  8. let userInteres = userInteresTextFIeld.text!
  9. let userPassword = userPasswordTextField.text!
  10. let oblojka = self.userBG.image!
  11. let avatar = self.userAva.image!
  12. let id = NSUserDefaults.standardUserDefaults().valueForKey("ID") as? String
  13.  
  14. let url = NSURL(string: "http://localhost/userProfile.php")
  15. let request = NSMutableURLRequest(URL: url!)
  16. request.HTTPMethod = "POST"
  17.  
  18. let posting = "id=(id)nameuser=(userName)&age=(userAge)&password=(userPassword)&email=(userEmail)&phone=(userPhone)&interes=(userInteres)"
  19. request.HTTPBody = posting.dataUsingEncoding(NSUTF8StringEncoding)
  20.  
  21.  
  22. let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
  23. data, response, error in
  24.  
  25. if error != nil
  26. {
  27. print("error=(error)")
  28. return
  29. }
  30.  
  31.  
  32. do {
  33. let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers) as? NSDictionary
  34.  
  35. if let parseJSON = json {
  36. print("Ошибка тут 2")
  37. let resultValue = parseJSON["status"] as? String
  38. print(resultValue)
  39. self.myImageUploadRequestAva()
  40. self.displayMyAlertMessage("Данные были успешно изменены!")
  41. }
  42. }
  43. catch {
  44. print(error)
  45. }
  46.  
  47.  
  48. }
  49.  
  50. task.resume()
  51.  
  52. }
  53.  
  54. <?php
  55.  
  56. require("Conn.php");
  57. require("MySQLDao.php");
  58.  
  59.  
  60. if(isset($_POST['email'])) {
  61. $email = $_POST['email'];
  62. $email = htmlentities($email);
  63. }
  64. if(isset($_POST['password'])){
  65. $password = $_POST["password"];
  66. $password = htmlentities($password);
  67. }
  68. if(isset($_POST['age'])){
  69. $age = $_POST["age"];
  70. $age = htmlentities($age);
  71. }
  72. if(isset($_POST['phone'])){
  73. $phone = $_POST["phone"];
  74. $phone = htmlentities($phone);
  75. }
  76.  
  77. if(isset($_POST['interes'])){
  78. $interes = $_POST["interes"];
  79. $interes = htmlentities($interes);
  80. }
  81. if(isset($_POST['id'])){
  82. $id = $_POST["id"];
  83. $id = htmlentities($id);
  84. }
  85. if(isset($_POST['nameuser'])){
  86. $name = $_POST["nameuser"];
  87. $name = htmlentities($name);
  88. }
  89.  
  90. if(isset($_POST['id'])) {
  91. $id = $_POST['id'];
  92. }
  93.  
  94.  
  95. if(isset($_POST['photo'])){
  96. $photo = $_POST["photo"];
  97. $photo = "/img/'".$photo."'";
  98.  
  99. $target_dir = "/img/";
  100.  
  101. $uploaddir = dirname(getcwd()).'/img/';
  102. $uploadfile = $uploaddir . basename($_FILES['file']['name']);
  103.  
  104. if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
  105. echo json_encode([
  106. "Message" => "The file ". basename($_FILES["file"]["name"]). " has been uploaded.",
  107. "Status" => "OK"
  108. ]);
  109. }
  110. else {
  111. $oblojka = "/img/avapepsi.jpg";
  112. }
  113. }
  114.  
  115. else {
  116. $photo = "/img/noava.png";
  117. }
  118.  
  119. if(isset($_POST['oblojka'])){
  120. $oblojka = $_POST["oblojka"];
  121. $oblojka = "/img/'".$oblojka."'";
  122.  
  123. $uploaddir = dirname(getcwd()).'/img/';
  124. $uploadfile = $uploaddir . basename($_FILES['file']['name']);
  125.  
  126. if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
  127. echo json_encode([
  128. "Message" => "The file ". basename($_FILES["file"]["name"]). " has been uploaded.",
  129. "Status" => "OK"
  130. ]);
  131. } else {
  132. $oblojka = "/img/avapepsi.jpg";
  133. }
  134.  
  135. } else {
  136. $oblojka = "/img/avapepsi.jpg";
  137. }
  138.  
  139.  
  140. $returnValue = array();
  141.  
  142. $secure_password = $password;
  143.  
  144. $dao = new MySQLDao();
  145. $dao->openConnection();
  146. $userProfile = $dao->updateProfile($id,$photo,$oblojka,$name,$email,$secure_password,$interes,$phone,$age);
  147.  
  148. if(!empty($userProfile)){
  149. $returnValue["status"] = "Success";
  150. $returnValue["message"] = "User is update";
  151. echo json_encode($returnValue);
  152. }
  153. else {
  154. $returnValue["status"] = "error";
  155. $returnValue["message"] = "User is not update";
  156. echo json_encode($returnValue);
  157. }
  158.  
  159. $dao->closeConnection();
  160.  
  161. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement