i am trying to save data from my app to my database, but i can not find, why it is not working. I was using tutorial from youtube, but it does not work for me.
this is my php file:
<?php
$host="localhost";
$user="admin_aplikace";
$password="A9Qgez0zX3";
$connection = mysql_connect($host,$user,$password);
$name = $_POST["a"];
$age = $_POST["b"];
if(!$connection){
die("Connection Failed");
}
else{
$dbconnect = @mysql_select_db("admin_aplikace", $connection);
if(!$dbconnect){
die("Could not connect to Database");
}
else{
$query = "INSERT INTO `zkouska2`(`bla`, `prvni`, `druha`) VALUES ([value-1],[$name],[$age])";
mysql_query($query, $connection) or die(mysql_error());
echo "Successfully added.";
echo $query;
}
}
?>
and this is my swift code:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var age: UITextField!
@IBOutlet weak var name: UITextField!
@IBAction func submit(_ 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://myserver/zkouska2.php")! as URL)
request.httpMethod = "POST"
let postString = "a=\(name.text!)&b=\(age.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
}
print("response = \(String(describing: response))")
let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
print("responseString = \(String(describing: responseString))")
}
task.resume()
}
and my errors:
NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}) error=Optional(Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x60000005faa0 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=http://servis.dronysitmp.cz/zkouska2.php, NSErrorFailingURLKey=http://servis.dronysitmp.cz/zkouska2.php, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.})