Discussion Forums  >  Config Data, JSON, App Refresh

Replies: 7    Views: 174

Antonios
Apple Fan
Profile
Posts: 381
Reg: Feb 12, 2013
Korinthos, Gree...
4,610
03/20/13 05:45 PM (11 years ago)

mySQL question

I want to create an app with a web form,PHP code and a mySQL database so the user can input some info (like a client database). I want the mySQL database to get syncronized with the database I am having at my server (HOSTGATOR) whenever iphone is connected to internet. Is this able?
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/20/13 05:53 PM (11 years ago)
if you know what you're doing, yes. Here's how you would send a few form fields to an online php script: NSString *post =[NSString stringWithFormat:@"%@=%@&%@=%@&%@=%@",field1, value1, field2, value2, field3, value3]; NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:phpScriptURL]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; NSError *error; NSURLResponse *response; NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; NSLog(@"%@", data);
 
Antonios
Apple Fan
Profile
Posts: 381
Reg: Feb 12, 2013
Korinthos, Gree...
4,610
like
03/20/13 05:59 PM (11 years ago)
you are the best!!! when I have the app ready I'll post the results here.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/20/13 06:00 PM (11 years ago)
happy to help :)
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/20/13 06:29 PM (11 years ago)
Nice stuff, Chris! Cheers! -- Smug
 
epicweb
Aspiring developer
Profile
Posts: 159
Reg: Aug 30, 2012
Glen Carbon
4,990
like
03/20/13 09:22 PM (11 years ago)
Awesome share Chris... any idea on how to alert if internet connection is not available so that the user knows nothing is happening?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/20/13 10:31 PM (11 years ago)
I use this snippet in my app, with the assumption that 'google' is active... Reachability *r = [Reachability reachabilityWithHostName:@"m.google.com"]; NetworkStatus internetStatus = [r currentReachabilityStatus]; if(internetStatus == NotReachable){ NSLog(@"There's no connection"); UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"No internet connection" message:@"Internet connection is required to use this app" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [errorAlertView show]; }else NSLog(@"Internet connection is OK"); } I place this is my "appDidFinishLaunching" code, but if you're just worried about a particular plugin, you can put it in the "viewDidLoad" method, with pretty much the same results. I don't think I had to add any imports or anything... Let me know if it weirds out on you. Cheers! -- Smug
 
epicweb
Aspiring developer
Profile
Posts: 159
Reg: Aug 30, 2012
Glen Carbon
4,990
like
03/21/13 06:14 AM (11 years ago)
Thank you Smug
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.