Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Uploading to MySQL Database

ghostghost Posts: 275Registered Users @ @
edited March 2010 in iOS SDK Development
Is there an easy way to upload to a MySQL database?
Is there an HTTP Post command?

How would I use it?

Thanks!
Post edited by ghost on

Replies

  • mxweasmxweas Posts: 142Registered Users
    edited August 2008
  • ghostghost Posts: 275Registered Users @ @
    edited August 2008
    I'm not registered there... would you mind copy/pasting the info?

    THanks!!
  • Jeremy1026Jeremy1026 Posts: 1,096Registered Users @ @ @ @
    edited August 2008
    ghost wrote: »
    I'm not registered there... would you mind copy/pasting the info?

    THanks!!

    Thats ok, I just registered to look it over, and it still wont.
    <a href="http://www.1026dev.com/55555_contest"; target="_blank">1026 Development's Bingo World Wide 55,555th Winner Contest</a><br />
    <a href="http://itunes.apple.com/us/app/bingo-world-wide/id291539020?mt=8"; target="_blank">bingo
  • mxweasmxweas Posts: 142Registered Users
    edited August 2008
    You need to be approved there... Everything is protected for NDA reasons.

    Max
  • ghostghost Posts: 275Registered Users @ @
    edited August 2008
    sooo in the meantime, how long does it take to get approved and is there any other resource?

    Thanks!
  • mxweasmxweas Posts: 142Registered Users
    edited August 2008
    I turned off the approval requirement for registered users for now.

    Max
  • ghostghost Posts: 275Registered Users @ @
    edited August 2008
    thanks! I just registered.

    But there must be an easier way! If my PHP page on the server uses "GET", can I just browse to that php page to upload the info? Is there a way to go to a webpage without displaying it?

    Thanks!
  • mxweasmxweas Posts: 142Registered Users
    edited August 2008
    NSData's dataWithContentsOfURL will make an NSData with the html of the page, thus calling it. I suggest this NSString method below to make your data URL safe if you plan to pass data using GET:
    - (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding
    

    Max
  • ghostghost Posts: 275Registered Users @ @
    edited August 2008
    Sorry... but I'm still confused :(

    How would I use that method? Is there something simple where I can just pass in the URL?

    Thanks!
  • mkrollmkroll Posts: 15Registered Users
    edited August 2008
    Hi,
    try this link:

    CocoaDev: HTTPFileUpload

    It helped me a lot.
    Using this procedure I was able to upload an image to a Java Servlet and additional parameters such as longitude and latitude.

    Good luck,
    Michael.
  • mxweasmxweas Posts: 142Registered Users
    edited August 2008
    If you need to upload files you may also use NSURLConnection and specify the request body with an NSMutableRequest.

    Max
  • ghostghost Posts: 275Registered Users @ @
    edited August 2008
    Thank you! This code seems perfect:
    - (IBAction)sendHTTPPost:(id)sender {
    	
    	//creating the url request:
    	NSURL *cgiUrl = [NSURL URLWithString:@"http://www.myserver.com/webToEmail.cgi"];
    	NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:cgiUrl];
    	
    	//adding header information:
    	[postRequest setHTTPMethod:@"POST"];
    	
    	NSString *stringBoundary = [NSString stringWithString:@"0xKhTmLbOuNdArY"];
    	NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",stringBoundary];
    	[postRequest addValue:contentType forHTTPHeaderField: @"Content-Type"];
    	
    	
    	//setting up the body:
    	NSMutableData *postBody = [NSMutableData data];
    	[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
    	[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"realname\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    	[postBody appendData:[[NSString stringWithString:@"Joe Doe"] dataUsingEncoding:NSUTF8StringEncoding]];
    	[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
    	[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"email\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    	[postBody appendData:[[NSString stringWithString:@"joe.doe@company.biz"] dataUsingEncoding:NSUTF8StringEncoding]];
    	[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
    	[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"uploadFile\"; filename=\"test.txt\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    	[postBody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    	[postBody appendData:[NSData dataWithContentsOfFile:@"/test.txt"]];
    	[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
    	[postRequest setHTTPBody:postBody];
    	
    	//sending the request via the 'htmlView' WebView:
            [[htmlView mainFrame] loadRequest:postRequest];
    }
    
  • cleverappscleverapps Posts: 11Registered Users
    edited August 2008
    ghost wrote: »
    Is there an easy way to upload to a MySQL database?
    Is there an HTTP Post command?

    How would I use it?

    Thanks!

    SocketWrapper - entropydb - Google Code - How to use the socket wrapper
  • mxweasmxweas Posts: 142Registered Users
    edited August 2008
    mxweas wrote: »
    NSData's dataWithContentsOfURL will make an NSData with the html of the page, thus calling it. I suggest this NSString method below to make your data URL safe if you plan to pass data using GET:
    - (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding
    

    Max

    to use this method and just pass the url you would do something like this:
    NSString *var1 = [ @"Hello World" stringByAddingPercentEscapesUsingEncoding: 4 ];
    NSString *var2 = [ @"This is some very long text that has quotes ' ' and other URL unsafe characters like spaces and double quotes \" \" and colons : and semi-colons ;" stringByAddingPercentEscapesUsingEncoding: 4 ];
    NSString *myURL = [ NSString stringWithFormat: @"http://mxweas.com/myApp/upload.php?var1=%@&var2=%@", var1, var2 ];
    
    [ NSData dataWithContentsOfURL: [ NSURL URLWithString: myURL ] ];
    

    the method I call on var1 and var2 make the text URL safe btw.

    Max
  • ghostghost Posts: 275Registered Users @ @
    edited August 2008
    So would something like this upload the stuff:
    NSString *lat = [ @"-12.3242" stringByAddingPercentEscapesUsingEncoding: 4 ];
    NSString *lon = [ @"65.35345" stringByAddingPercentEscapesUsingEncoding: 4 ];
    NSString *carrier = [ @"ATT" stringByAddingPercentEscapesUsingEncoding: 4 ];
    NSString *reception = [ @"7" stringByAddingPercentEscapesUsingEncoding: 4 ];
    NSString *myURL = [ NSString stringWithFormat: @"http://receptionmap.com/upload.php?lat=%@&lon=%@&carrier=%@&reception=%@", lat, lon, carrier, reception ];
    
    [ NSData dataWithContentsOfURL: [ NSURL URLWithString: myURL ] ];
    

    Would I need anything else? Would this connect and upload?

    Thanks for your help!
  • mxweasmxweas Posts: 142Registered Users
    edited August 2008
    yup, the return response of upload.php will be returned by the last line if you choose to use it. Otherwise you can ignore it because its autoreleased.

    Max
  • ghostghost Posts: 275Registered Users @ @
    edited August 2008
    Do I need to import anything or use a framework? My code looks like this at the moment:
    #import "MainView.h"
    
    @implementation MainView
    
    @synthesize latitudeText;
    @synthesize longitudeText;
    @synthesize carrierText;
    @synthesize receptionText;
    @synthesize loadingText;
    
    
    - (IBAction)start {
        loadingText.text = @"Starting...";
    	
    	NSString *lat = [ @"-12.3242" stringByAddingPercentEscapesUsingEncoding: 4 ];
    	NSString *lon = [ @"65.35345" stringByAddingPercentEscapesUsingEncoding: 4 ];
    	NSString *carrier = [ @"ATT" stringByAddingPercentEscapesUsingEncoding: 4 ];
    	NSString *reception = [ @"7" stringByAddingPercentEscapesUsingEncoding: 4 ];
    	loadingText.text = @"Sending...";
    	NSString *myURL = [ NSString stringWithFormat: @"http://receptionmap.com/upload.php?lat=%@&lon=%@&carrier=%@&reception=%@", lat, lon, carrier, reception ];
    	[ NSData dataWithContentsOfURL: [ NSURL URLWithString: myURL ] ];
    	loadingText.text = @"Sent!";
    }
    
    
    
    
    @end
    
    But it just freezes when I press the button.
    Thanks!
  • claijonclaijon Posts: 1New Users
    edited July 2009
    Ghost,

    Did you make it work? I'm starting to develop and will need to talk to mysql too.
    Please let me know what you ended up with.
  • gemsgems Posts: 23Registered Users
    edited March 2010
    mxweas wrote: »
    to use this method and just pass the url you would do something like this:
    NSString *var1 = [ @"Hello World" stringByAddingPercentEscapesUsingEncoding: 4 ];
    NSString *var2 = [ @"This is some very long text that has quotes ' ' and other URL unsafe characters like spaces and double quotes \" \" and colons : and semi-colons ;" stringByAddingPercentEscapesUsingEncoding: 4 ];
    NSString *myURL = [ NSString stringWithFormat: @"http://mxweas.com/myApp/upload.php?var1=%@&var2=%@", var1, var2 ];
    
    [ NSData dataWithContentsOfURL: [ NSURL URLWithString: myURL ] ];
    

    the method I call on var1 and var2 make the text URL safe btw.

    Max

    Sir,
    Is it working for your app? if yes then plz tell us how. i have to deal with the same. no dought iam trying first but i need your help also
    thanks
    Mahesh:(
Sign In or Register to comment.