获取错误域= NSCocoaErrorDomain代码= 3840"没有值。"

时间:2016-02-16 13:07:22

标签: php sql swift

当我尝试通过swift

中的php在我的SQL数据库中插入数据时,我收到此错误

我不确定为什么我会收到此错误。我是新手,并且真的坚持这种情况

错误即时获取:

  Error Domain=NSCocoaErrorDomain Code=3840 "No value." 
 UserInfo={NSDebugDescription=No value.}

这是我的快速代码

     let myURL = NSURL(string: "http://localhost:8888/userRegister.php");
        let request =   NSMutableURLRequest(URL: myURL!);
        request.HTTPMethod = "POST";

        let postString = "email=\(username)&password=\(password)&firstName=\(firstName)"

        print(postString)


        request.HTTPBody = postString.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{
                    let resultValue = parseJSON["status"] as! String!
                    print("result:\(resultValue)")

                    var isUserRegistered: Bool = false;
                    if(resultValue == "success"){
                        isUserRegistered = true;
                    }
                    var messageToDisplay:String = parseJSON["message"] as! String!;
                    if (!isUserRegistered)
                    {
                        messageToDisplay = parseJSON["message"] as! String!;
                    }

                    dispatch_async(dispatch_get_main_queue(), {
                        let myAlert = UIAlertController(title: "Alert", message: messageToDisplay, preferredStyle: UIAlertControllerStyle.Alert);
                        let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default){ action in

                            self.dismissViewControllerAnimated(true, completion: nil);
                        };

                        myAlert.addAction(okAction);
                        self.presentViewController(myAlert, animated: true, completion: nil);
                        }


                    )};


            } catch { print(error)}
        }

        task.resume();

和我的php:

$email = htmlentities($_POST["email"]);
$password = htmlentities($_POST["password"]);
$firstName = htmlentities($_POST["firstName"]);§

$result = $dao->registerUser($email,$secure_password,$firstName);

if($result) 
{
$returnValue["status"] = "Success";
$returnValue["message"] = "User is registered";
echo json_encode($returnValue);
return; 
}

public function registerUser($email, $password, $firstName)
{
$sql = "insert into users set username=?, password=?,firstName=?";
$statement = $this->conn->prepare($sql);

if (!$statement)
throw new Exception($statement->error);

$statement->bind_param("sss", $email, $password, $firstName);
$returnValue = $statement->execute();

return $returnValue;
}

}

提前谢谢

0 个答案:

没有答案