-2

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);}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
kenzolek
  • 344
  • 6
  • 24
  • You are mixing mysql_ calls with mysqli_ or PDO calls ( Not quite sure which ) **that wont work** – RiggsFolly Sep 14 '15 at 09:42
  • So in app is everything ok, right? Only my php file is not correct? I was working with this tutorial: https://www.youtube.com/watch?v=v1Jdrit4PfE and there data is completly insert to mysql. – kenzolek Sep 14 '15 at 10:34
  • No idea about app, PHP is a mess – RiggsFolly Sep 14 '15 at 10:37

1 Answers1

1

Encode Base64 your data and then try to submit to MySql, Maybe you have any specific characters.

NSString *plainString = @"Any text ..... bla bla bla";

NSData *plainData = [plainString dataUsingEncoding:NSUTF8StringEncoding];
NSString *base64String = [plainData base64EncodedStringWithOptions:0];
NSLog(@"%@", base64String); 
Grigori Jlavyan
  • 1,871
  • 3
  • 19
  • 39