Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.}
- @IBAction func userSaveInfoButtonTapped(sender: AnyObject) {
- let userName = userNameTextField.text!
- let userAge = userAgeTextField.text!
- let userPhone = userPhoneTextFIeld.text!
- let userEmail = userEmailTextField.text!
- let userInteres = userInteresTextFIeld.text!
- let userPassword = userPasswordTextField.text!
- let oblojka = self.userBG.image!
- let avatar = self.userAva.image!
- let id = NSUserDefaults.standardUserDefaults().valueForKey("ID") as? String
- let url = NSURL(string: "http://localhost/userProfile.php")
- let request = NSMutableURLRequest(URL: url!)
- request.HTTPMethod = "POST"
- let posting = "id=(id)nameuser=(userName)&age=(userAge)&password=(userPassword)&email=(userEmail)&phone=(userPhone)&interes=(userInteres)"
- request.HTTPBody = posting.dataUsingEncoding(NSUTF8StringEncoding)
- let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
- data, response, error in
- if error != nil
- {
- print("error=(error)")
- return
- }
- do {
- let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers) as? NSDictionary
- if let parseJSON = json {
- print("Ошибка тут 2")
- let resultValue = parseJSON["status"] as? String
- print(resultValue)
- self.myImageUploadRequestAva()
- self.displayMyAlertMessage("Данные были успешно изменены!")
- }
- }
- catch {
- print(error)
- }
- }
- task.resume()
- }
- <?php
- require("Conn.php");
- require("MySQLDao.php");
- if(isset($_POST['email'])) {
- $email = $_POST['email'];
- $email = htmlentities($email);
- }
- if(isset($_POST['password'])){
- $password = $_POST["password"];
- $password = htmlentities($password);
- }
- if(isset($_POST['age'])){
- $age = $_POST["age"];
- $age = htmlentities($age);
- }
- if(isset($_POST['phone'])){
- $phone = $_POST["phone"];
- $phone = htmlentities($phone);
- }
- if(isset($_POST['interes'])){
- $interes = $_POST["interes"];
- $interes = htmlentities($interes);
- }
- if(isset($_POST['id'])){
- $id = $_POST["id"];
- $id = htmlentities($id);
- }
- if(isset($_POST['nameuser'])){
- $name = $_POST["nameuser"];
- $name = htmlentities($name);
- }
- if(isset($_POST['id'])) {
- $id = $_POST['id'];
- }
- if(isset($_POST['photo'])){
- $photo = $_POST["photo"];
- $photo = "/img/'".$photo."'";
- $target_dir = "/img/";
- $uploaddir = dirname(getcwd()).'/img/';
- $uploadfile = $uploaddir . basename($_FILES['file']['name']);
- if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
- echo json_encode([
- "Message" => "The file ". basename($_FILES["file"]["name"]). " has been uploaded.",
- "Status" => "OK"
- ]);
- }
- else {
- $oblojka = "/img/avapepsi.jpg";
- }
- }
- else {
- $photo = "/img/noava.png";
- }
- if(isset($_POST['oblojka'])){
- $oblojka = $_POST["oblojka"];
- $oblojka = "/img/'".$oblojka."'";
- $uploaddir = dirname(getcwd()).'/img/';
- $uploadfile = $uploaddir . basename($_FILES['file']['name']);
- if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
- echo json_encode([
- "Message" => "The file ". basename($_FILES["file"]["name"]). " has been uploaded.",
- "Status" => "OK"
- ]);
- } else {
- $oblojka = "/img/avapepsi.jpg";
- }
- } else {
- $oblojka = "/img/avapepsi.jpg";
- }
- $returnValue = array();
- $secure_password = $password;
- $dao = new MySQLDao();
- $dao->openConnection();
- $userProfile = $dao->updateProfile($id,$photo,$oblojka,$name,$email,$secure_password,$interes,$phone,$age);
- if(!empty($userProfile)){
- $returnValue["status"] = "Success";
- $returnValue["message"] = "User is update";
- echo json_encode($returnValue);
- }
- else {
- $returnValue["status"] = "error";
- $returnValue["message"] = "User is not update";
- echo json_encode($returnValue);
- }
- $dao->closeConnection();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement