I'm new to the ios programming and i'm trying to connect the ios app to mysql server and i'm getting the error as below i have posted please help me regarding this. below is my php script
<?php
$host = ’localhost’;
$user = ‘’;
$password = ‘’;
$connection = mysqli_connect($host,$user,$password);
$fname = $_POST[‘a’];
$lname = $_POST[‘b’];
$school = $_POST[‘c’];
if(!$connection){
die(‘connection failed’);
}
else{
$dbconnect = @mysqli_select_db(‘pnallama’,$connection);
if(!$dbconnect){
die(‘connection to DB failed’);
}
else{
$query = “INSERT INTO ‘pnallama’.’DataCollector’ (‘firstname’, ‘lastname’, ‘school’) VALUES (‘$fname’, ‘$lname’, ‘$school’);”;
mysqli_query($query, $connection) or die(mysqli_error());
echo ‘successfully added’;
echo $query;
}
}
?>
and my view controller is
import UIKit
class CollectorDetailView: UIViewController, UITextFieldDelegate {
@IBOutlet weak var textField1: UITextField! = nil
@IBOutlet weak var textField2: UITextField! = nil
@IBOutlet weak var textField3: UITextField! = nil
@IBAction func submitBtnPressed(_ sender: UIButton) {
let request = NSMutableURLRequest(url: NSURL(string: "http://kindlewell.com/~pnallama/insert.php")! as URL)
request.httpMethod = "POST"
let postString = "a=\(textField1.text!)&b=\(textField2.text!)&c=\(textField3.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
}
print("response=\(response)")
let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
print("responseString =\(responseString)")
}
task.resume()
}
override func viewDidLoad() {
super.viewDidLoad()
textField1.delegate = self
textField2.delegate = self
textField3.delegate = self
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool // called when 'return' key pressed. return NO to ignore.
{
textField.resignFirstResponder()
return true;
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
and i'm getting an error like this
response=Optional(<NSHTTPURLResponse: 0x60800022ad60> { URL: http://kindlewell.com/~pnallama/insert.php } { status code: 500, headers {
Connection = close;
"Content-Length" = 0;
"Content-Type" = "text/html";
Date = "Wed, 12 Oct 2016 06:31:26 GMT";
Server = "Apache/2.4.6 (Linux/SUSE)";
"X-Powered-By" = "PHP/5.4.20, Mono";
} })
(lldb)