1
私はmysqlの とswift3の登録をしようとしていますと3が、間違っているいくつかのことがあり、 私は私のアプリを実行し、PHPコードで迅速MySQLの
「いくつかのフィールドが空で、」レジスタリターンMSGを行うとき:
$fullname = htmlentities($_REQUEST["fullname"]);
$username = htmlentities($_REQUEST["username"]);
$email = htmlentities($_REQUEST["email"]);
$password = htmlentities($_REQUEST["password"]);
$phone = htmlentities($_REQUEST["phone"])
SWIFTコード:
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config)
let url = URL(string: "http://localhost/php/register.php?")
var request = URLRequest(url: url!)
request.httpMethod = "POST"
let body = "fullname=\(FirstName.text)%20\(LastName.text)&username=\(UserName.text)&email=\(Email.text)&password=\(Password.text)&phone=\(Phone.text)"
request.httpBody = body.data(using: String.Encoding.utf8)
let task = session.dataTask(with: url!) {data, response, error in
if error != nil {
print(error!.localizedDescription)
} else {
do {
if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any]
{
print(json)
}
} catch {
print("error in JSONSerialization")
}
}
}
task.resume()
で
url
を置き換えます。第二に、あなたのPHPファイルに '$ _POST'を記録することができます:' file_put_contents( 'log.txt'、json_encode($ _ POST、JSON_PRETTY_PRINT)); ' – Blag