I'm trying insert data to MySQL with JSON format but it is not working. The data is not insert to database. Could you tell what I'm doing wrong? This is my PHP file:
<?php
$con = mysql_connect("http://mydomain", "dbUserName", "password");
if(!$con)
{
die('Connect fail', mysql_error());
}
mysql_select_db("dbName", $con);
if(isset($_REQUEST['data']))
{
$json = $_REQUEST['data'];
$data = json_decode($json);
mysql_query("INSERT INTO tbAccount
(AccFullName, AccAboutMe)
VALUES ('$data->AccFullName', '$data->AccAboutMe')");
}
$con->exec($mysql_query);
echo "New record created successfully";
mysql_close($con);?>
and implementation .m in app in obj-c:
- (IBAction)insert:(id)sender;{NSMutableString *postString = [NSMutableString stringWithString:kPostURL];
NSString *jsonString = [[NSString alloc] initWithFormat:@"{\"AccFullName\":\"%@\", \"AccAboutMe\":\"%@\"}", self.name.text, aboutMe.text];
[postString appendString:[NSString stringWithFormat:@"?data=%@", jsonString]];
[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];
NSLog(@"Post string %@", postString);}