Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // FootBall_Social
- //
- // Created by Khanh Nguyen on 3/25/17.
- // Copyright © 2017 Khanh Nguyen. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController {
- @IBOutlet weak var textFieldUser: UITextField!
- @IBOutlet weak var textFieldPassword: UITextField!
- @IBOutlet weak var labelMessage: UILabel!
- @IBAction func Login(_ sender: Any) {
- //put the link of the php file here. The php file connects the mysql and swift
- let request = NSMutableURLRequest(url: NSURL(string: "http://rectangletest.byethost7.com/testpost.php")! as URL)
- request.httpMethod = "POST"
- let postString = "a=\(textFieldUser.text!)&b=\(textFieldPassword.text!)"
- request.httpBody = postString.data(using: String.Encoding.utf8)
- let task = URLSession.shared.dataTask(with: request as URLRequest) {
- data, response, error in
- if error != nil {
- print("error=\(error)")
- return
- }
- let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
- print("responseString = \(responseString)")
- }
- task.resume()
- let alertController = UIAlertController(title: "Candidate's Name", message:
- "Successfully Added", preferredStyle: UIAlertControllerStyle.alert)
- alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default,handler: nil))
- self.present(alertController, animated: true, completion: nil)
- textFieldUser.text = ""
- textFieldPassword.text = ""
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement