I am trying to use Xcode textfields to post onto my mysql server. The issue is that i don't get errors in Xcode or php but the post never gets inserted into my mysql table. I know the url is right as well as the username and password and dbname etc. Here is my code when the submit button is pressed in Xcode:
NSString * post = [[NSString alloc] initWithFormat:@"message=test&name=%@", name.text];
NSData * postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8888/Upload.php"]]]
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];
NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[conn start];
if (conn) NSLog(@"Connection Successful");
my php looks like this:
<?php
/*
Johnny
JUL, 2011
*/
$DB_HostName = "localhost";
$DB_Name = "test";
$DB_User = "root";
$DB_Pass = "root";
$DB_Table = "test";
$con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die(mysql_error());
mysql_select_db($DB_Name) or die(mysql_error());
$name = $_POST["name"];
$message = $_POST["message"];
$query = "INSERT INTO Locations('name','message') VALUES('$name','$message')";
mysql_query($query) or die(mysql_error("error"));
mysql_close();
?>