0

I was following a video tutorail online to send data to a php file then store that in a database.

I'm really confused how it evan works as theres not post? Its just collecting information from variables. I few youtube comments say the same thing, but some how his works?

My code so far...

- (IBAction)Submit:(id)sender {

    NSString *strURL = [NSString stringWithFormat:@"http://www.bigwavemedia.co.uk/ios/contact.php?name=%@", nameField.text];

    //to execute php code
    NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];

    NSString *strRes = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

    NSLog(@"%@", strRes);  
}

When I hit the submit button, evan though its linked up I get no response?

Brent
  • 2,385
  • 10
  • 39
  • 63

1 Answers1

1

In Your case you Need to create NSURLConnection for communication to server.

NSString *strURL=[NSString stringWithFormat:@"http://www.bigwavemedia.co.uk/ios/contact.php?name=%@", nameField.text];

NSURL *url=[NSURL URLWithString:strURL];
self.request=[NSURLRequest requestWithURL:url];

self.nsCon=[[NSURLConnection alloc] initWithRequest:request delegate:self];

            if(self.nsCon)
                self.receivedData=[[NSMutableData alloc] init];
            else
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error",@"") message:NSLocalizedString(@"Not Connected Other View !!",@"") delegate:nil cancelButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitles:nil];
                [alert show];
                [alert release];
            }

And Write require delegate method of NSURLConnection, that describe in above link.

iPatel
  • 46,010
  • 16
  • 115
  • 137
  • Where do I add this delegate? I opened the .h file and added @interface ContactViewControler : UIViewController is this correct? – Brent Mar 06 '13 at 14:51
  • yes...it is correct..or many exmple on google search it :) thanks :) – iPatel Mar 06 '13 at 14:54
  • Sorry im confused on the last bit? Thanks – Brent Mar 06 '13 at 14:54
  • Could you please take a look at image link, its showing red on code i used, cant understand why. – Brent Mar 06 '13 at 14:58
  • it is object that decalre in .h file and use with self.obj_Name in .m file ...it is very simple bro :) – iPatel Mar 06 '13 at 14:59
  • I will mark it correct just need to fix the .h then i guess, heres is a image of what i got. http://s13.postimage.org/9gdeziy6f/Screen_Shot_2013_03_06_at_15_02_20.png Sorry this is my first week on xcode and im trying to learn as much as i can. – Brent Mar 06 '13 at 15:03
  • @iPatel : can you take a look at [this question](http://stackoverflow.com/questions/17061813/arabic-text-getting-stored-as) – Fahim Parkar Jun 12 '13 at 14:45