I'm trying to send data over from my iOS app to a PHP script. I have Title, Description and City. I want it to always save every info I send to it from my iOS app and always make a new one every time I send it data. The problem I'm having is, when I go to the PHP file on my browser, nothing shows up. The title, description and city field is always blank. But in my Xcode console I see it returning everything correctly. Here's my swift code.
func postToServerFunction() {
var url: NSURL = NSURL(string: "http://vittletest.netii.net/index.php")!
var request:NSMutableURLRequest = NSMutableURLRequest(URL:url)
request.HTTPMethod = "POST"
let postString = "title=testing&description=hello&city=RanchoCordova"
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
if error != nil {
println("error=\(error)")
return
}
println("response = \(response)")
let responseString = NSString(data: data, encoding: NSUTF8StringEncoding)
println("responseString = \(responseString)")
}
task.resume()
}
And here's my PHP file.
<?php
$something = "Some Info";
echo $something;
$title = $_POST['title'];
$description = $_POST['description'];
$city = $_POST['city'];
echo "<br />";
echo "Title: ". $title;
echo "<br />";
echo "Description: ". $description;
echo "<br />";
echo "City: ". $city;
?>
And here's my console output on Xcode.
2015-01-03 10:05:50.861 VittleTest[616:28516] Warning: A long-running operation is being executed on the main thread.
Break on warnBlockingOperationOnMainThread() to debug.
response = <NSHTTPURLResponse: 0x7f9f5ae5e3f0> { URL: http://vittletest.netii.net/index.php } { status code: 200, headers {
Connection = close;
"Content-Length" = 309;
"Content-Type" = "text/html";
Date = "Sat, 03 Jan 2015 18:05:52 GMT";
Server = Apache;
"X-Powered-By" = "PHP/5.2.17";
} }
responseString = Optional(<html>
<head>
<title>PHP Test</title>
</head>
<body>
Some Info<br />Title: testing<br />Description: hello<br />City: RanchoCordova
</body>
</html>
<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->
)
I hope I gave you guys enough info to help me out because I can't seem to figure it out since I'm not the best with PHP.