views:

211

answers:

3

Hi, I wanted to ask if anyone could help he get this code to work. Nothing is showing up in my MySQL database. Thanks, enbr.

NSString *urlstr = [[NSString alloc] initWithFormat:@"http://mysite.come/myapp/submitrating.php?name=%@&comment=%@&rating=%@",
                    [selectedItem objectForKey:@"name"], comment.text, selectedRating];
NSString *urlstrEncoded = [urlstr stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [[NSURL alloc] initWithString:urlstrEncoded];
[urlstr release];
[url release];
+1  A: 

You're not doing anything with the URL object except creating it. Perhaps you want to try an NSURLConnection?

quixoto
+2  A: 

You need to do much more than that! At minimum you need the following:

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];



NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

along with implementing the following methods:

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
ennuikiller
I tried this method but it doesn't seem to be working for me.
enbr
A: 

I got it to work with this code.

NSString *urlstr = [NSString stringWithFormat:@"http://mysite.com/myapp/submitrating.php?name=%@&comment=%@&rating=%@", [selectedItem objectForKey:@"name"], comment.text, selectedRating];
NSString *urlEncoded = [urlstr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [[NSURL alloc] initWithString:urlEncoded];
NSString *ans = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:nil];
enbr