0

The code below is returning and error message:

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

I don't know how to resovle it.

This class take the content of Fields and it do an request to a php page that insert the fields in a database:

import UIKit

class RegViewController: UIViewController{

    //Fields
    @IBOutlet weak var Nome_reg: UITextField!
    @IBOutlet weak var Cognome_reg: UITextField!
    @IBOutlet weak var Mail_reg: UITextField!
    @IBOutlet weak var User_reg: UITextField!
    @IBOutlet weak var Psw_reg: UITextField!
    @IBOutlet weak var Psw_check: UITextField!

    //Buttons methods
    @IBAction func Conferma_Reg(sender: AnyObject) {


        let bodyString = "a=\(Nome_reg.text!)&b=\(Cognome_reg.text!)&c=\(User_reg.text!)&d=\(Mail_reg.text!)&f=\(Psw_reg.text!)"
        let bodyData = bodyString.dataUsingEncoding(NSUTF8StringEncoding)

        let request=NSMutableURLRequest(URL:NSURL(string:"http://mysite/MyFolder/registration.php")!)
        request.HTTPBody = bodyData
        request.HTTPMethod = "POST"


        let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in
            guard error == nil && data != nil else {
                print("error=\(error)")
                return
            }

            do {
                let responseObject = try NSJSONSerialization.JSONObjectWithData(data!, options: [])

                print(responseObject)
            } catch let parseError as NSError {
                print(parseError)
            }
        }
        task.resume()
    }

}
Tim Ogilvy
  • 1,923
  • 1
  • 24
  • 36
Alastair
  • 1
  • 1
  • Have you tested your php script with a standard browser and an html page contianing a `form method="post` element with the ncessary controls to "emulate" the request? – VolkerK Apr 02 '16 at 10:38
  • 1
    Now i'm checking... in your opinion my code is correct? the problem is in the php page? – Alastair Apr 02 '16 at 11:03
  • may be this may help you:http://stackoverflow.com/a/14171349/4557505 – HardikDG Apr 02 '16 at 11:47
  • i have checked my php and i see that Xcode display this error but data are stored into my database – Alastair Apr 03 '16 at 00:21

0 Answers0