这是我的快捷代码:
import UIKit
class SignUpViewController: UIViewController {
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var nameField: UITextField!
@IBOutlet weak var pwdField: UITextField!
@IBOutlet weak var pwdAgain: UITextField!
@IBAction func SignUpTapped(_ sender: UIButton) {
if pwdField.text == pwdAgain.text {
var request = URLRequest(url: NSURL(string: "sftp://....compute.amazonaws.com/var/www/html/register.php") as! URL) //... is hide my user name
request.httpMethod = "POST"
let postString = "email=\(emailField.text!)&name=\(nameField.text)&password=\(pwdField.text)"
request.httpBody = postString.data(using: String.Encoding.utf8)
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
if error != nil{
print("response = \(error)")
return
}
print("response = \(response)")
let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
print("responseString = \(responseString)")
}
task.resume()
}else if pwdAgain.text == "" || pwdField.text == "" || emailField.text == "" || nameField.text == ""{
let alert = UIAlertController(title: "Notification", message: "Please fill all block!", preferredStyle: UIAlertControllerStyle.alert)
self.present(alert, animated: true, completion: nil)
}else{
let alert = UIAlertController(title: "Notification", message: "Please enter same password twice!", preferredStyle: UIAlertControllerStyle.alert)
self.present(alert, animated: true, completion: nil)
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
和我的php代码:register.php
<?php
include 'dbConnect.php';
$email = $_POST['email'];
$name = $_POST['name'];
$pwd = $_POST['password'];
$id = date('mdHis');
$checkEmail = false;
$checkName = false;
$dbInsert = false;
if ($conn->query("SELECT * FROM fyp.blogger WHERE email='$email'")- >num_rows == 0) {
$checkEmail = true;
}
if ($conn->query("SELECT * FROM fyp.blogger WHERE name='$name'")->num_rows == 0) {
$checkName = true;
}
if ($checkName && $checkEmail) {
$dbInsert = $conn->query("INSERT INTO fyp.blogger (blogger_id,email,name,pwd) VALUES ($id, '$email','$name', '$pwd')");
}
$conn->close();
?>
问题是我尝试测试连接,就像阻止我一样。
以下错误:
有关于我使用sftp的事吗?我只想将一些数据保存到MYSQL数据库 并读取数据。 我希望任何人都可以解决问题。