Thursday 15 March 2012

php - Sending Data to Server Using Multiple View Controllers in ObjectiveC -



php - Sending Data to Server Using Multiple View Controllers in ObjectiveC -

my current programme i've made allows user input text text box sends info server when submit button pressed.

however, have multiple view controllers each own input boxes user input info into. example: vc1 has id , password text box, vc2 has age text box , vc3 has nationality text box.

is possible submit info every vc @ once? utilize single php file this?. quite confused concept help great !

my php code:

<?php $username = "root"; $database = "testdb"; mysql_connect('localhost', $username); @mysql_select_db($database) or die ("unable find database"); $name = @$_get["name"]; $message = @$_get["message"]; $query = "insert test values ('', '$name', '$message')"; mysql_query($query) or die (mysql_error("error")); mysql_close(); ?>

and obj c .h

#import <uikit/uikit.h> #define kposturl @"http://localhost/testconnect.php" //variable utilize whenever #define kname @"name" #define kmessage @"message" @interface firstviewcontroller : uiviewcontroller{ iboutlet uitextfield *nametext; iboutlet uitextview *messagetext; nsurlconnection *postconnection; } -(ibaction)post:(id)sender; @end

.m

#import "firstviewcontroller.h" @interface firstviewcontroller () @end @implementation firstviewcontroller - (void)viewdidload { [super viewdidload]; } -(void) postmessage:(nsstring*) message withname:(nsstring *) name{ if(name !=nil && message !=nil){ nsmutablestring *poststring = [nsmutablestring stringwithstring:kposturl]; [poststring appendstring:[nsstring stringwithformat:@"?%@=%@", kname, name]]; [poststring appendstring: [nsstring stringwithformat:@"&%@=%@", kmessage, message]]; [poststring setstring:[poststring stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]]; nsmutableurlrequest *request =[[nsmutableurlrequest alloc] initwithurl:[nsurl urlwithstring: poststring]]; [request sethttpmethod:@"post"]; postconnection =[[nsurlconnection alloc]initwithrequest:request delegate:self startimmediately:yes]; } } -(ibaction)post:(id)sender{ [self postmessage:messagetext.text withname:nametext.text]; [messagetext resignfirstresponder]; messagetext.text=nil; nametext.text=nil; } - (void)didreceivememorywarning { [super didreceivememorywarning]; } @end

how fields displayed? in single form, or in multiple forms?

you display of fields in single form, info form submitted in same $_post submit button on form action parameter in form.

if fields held on same page in different forms utilize javascript collect info , submit @ once.

if of fields on different views/pages, work around able pass of info @ once; pass $_post info 1 view next , set in hidden field, on lastly step, can submit of info @ once.

php ios objective-c xcode

No comments:

Post a Comment