I just want to ask on how to send textfield value into mysql database in xcode using obj c without any click action or with click action?
If the code below can retrieve and display JSON data from web server into xcode:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize username,email;
- (void)viewDidLoad {
[super viewDidLoad];
NSError *error;
NSString *url_string = [NSString stringWithFormat: @"http://localhost/test.php"];
NSData *data = [NSData dataWithContentsOfURL: [NSURL URLWithString:url_string]];
NSMutableArray *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSDictionary *dict = [json firstObject];
NSString *data1 = [dict valueForKey:@"username"];
NSString *data2 = [dict valueForKey:@"email"];
email.text = data1;
pw.text = data2;
}
@end
How to post username, email value into mysql database? Is it the same technique applied on post method? Because I do not want to use SBJson classes (if possible).
There are several ways to do it. First, it is important to notice that
dataWithContentsOfURL
is not an asynchronous request. Meaning that if you use it to transfer large data, there is a good chance that you will freeze the app. For async requests, you should use the NSURLRequest.Having said that, there are excellent API to upload/download data asynchronously. One which is very frequently used, and well documented is AFNetworking. This is coded on top of NSURLRequest.
For example, in your PHP you can retrieve the fields from a POST statement like this:
In your app, you can call the PHP script with a POST request in AFNetworking as follow:
Try this code: