This is my first question and I hope to get some help:
I've used several methods (and tried with different http transmission frameworks) to make a post action to a php script in localhost with no good results. I don't know what else to look for. I've been stuck with this for at least 6 or 7 hours and finally got to this:
Objective C code:
if (name != nil && message != nil) {
NSMutableString *postString = [NSMutableString stringWithString:TFPostURL];
[postString appendString:[NSString stringWithFormat:@"%@=%@",TFName,name]];
[postString appendString:[NSString stringWithFormat:@"%@=%@",TFMessage,message]];
[postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]];
[request setHTTPMethod:@"POST"];
postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
TFPostURL, TFName, TFMessage, name and message are constants defined by me.
I'm using the database just to check if the transmission has been successfully done:
PHP Script
<?php
$username = "root";
$database = "db";
mysql_connect(localhost, $username);
@mysql_select_db($database) or die("Unable to find database");
$name = $_POST["name"];
$message = $_POST["message"];
$query = "INSERT INTO test VALUES ('', '$name', '$message')";
mysql_query($query) or die(mysql_error("error"));
mysql_close();
?>
Any ideas on what would be wrong?
I've been tried always in localhost, still need to try this in another mac. I'm on my way to upload my php file to a public domain and check if it's something in my own computer.
Edit:
I've changed the PHP POST action to GET, obtaining amazing results; NOW IT WORKS!
<?php
$username = "root";
$database = "db";
mysql_connect(localhost, $username);
@mysql_select_db($database) or die("Unable to find database");
$name = $_GET["name"];
$message = $_GET["message"];
$query = "INSERT INTO test VALUES ('', '$name', '$message')";
mysql_query($query) or die(mysql_error("error"));
mysql_close();
?>