For my school’s project I’ve been working with iOS app and connecting it to mySQL database using php and phpmyadmin. I’ve created php file and successfully linked to the iOS app. The signUp process is working fine but I’ve a problem with the verification of username and password for log in process. I’ve included my code and the part where i need help with swift.
(I couldn’t figure out the swift coding part for login verifications with the database… i got correct results form the php file tho…as in the screenshot)
Please HELP !!!
here’s the code
// For Login
@IBOutlet weak var Uname: UITextField!
@IBOutlet weak var Pword: UITextField!
var a="a" ,r=0
@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://192.168.64.2/tryLogin.php")! as URL)
request.httpMethod = "POST"
let postString = "a=\(Uname.text!) & b=\(Pword.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=\(String(describing: error))")
return
}
else{
//print("response = \(String(describing: response))")
let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
self.a=(String(describing: responseString))
print(self.a)
}
}
task.resume()
// I NEED HELP FROM DOWN HERE ->
// if the username and password is correct
if ( ){
let alertController = UIAlertController(title: "Candidate", message: "Logged In", preferredStyle: UIAlertController.Style.alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default,handler: nil))
self.present(alertController, animated: true, completion: nil)
}
// if the username and password is incorrect
else{
let alertController = UIAlertController(title: "Candidate", message: "Incorrect info.", preferredStyle: UIAlertController.Style.alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default,handler: nil))
self.present(alertController, animated: true, completion: nil)
}
}
}