Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-08-2010, 04:25 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Hong Kong, China
Posts: 19
Default How to send/pass the data from iPhone to php?

I want to pass some data from iPhone to Php. Plz, anyone can help me to solve this problem.
Thx sooooooooooooooo much =)

My situation,

Now, i created the php file(*It can send email from server, and which is work).Then, I used the Interface Builder to created the interface view in my app. So, the user can use the iphone device (*OS 3.0 or above) to input their information (for example: email address, user's name, etc.) and press the "Send" button to send the data to php. But I dont want to open the browser to view the php in iphone directly.

sendEmail.php variable
$name = $_POST['firstName'];
$email = $_POST['emailAddress'];
ansonyik is offline   Reply With Quote
Old 03-08-2010, 05:27 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 44
Default

Quote:
Originally Posted by ansonyik View Post
I want to pass some data from iPhone to Php. Plz, anyone can help me to solve this problem.
Thx sooooooooooooooo much =)

My situation,

Now, i created the php file(*It can send email from server, and which is work).Then, I used the Interface Builder to created the interface view in my app. So, the user can use the iphone device (*OS 3.0 or above) to input their information (for example: email address, user's name, etc.) and press the "Send" button to send the data to php. But I dont want to open the browser to view the php in iphone directly.

sendEmail.php variable
$name = $_POST['firstName'];
$email = $_POST['emailAddress'];


Code:
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:@"http://www.website.nl/page.php"] autorelease];

[request setPostValue:@"YoseMite" forKey:@"firstName"];
[request setPostValue:@"mail@google.com" forKey:@"emailAddress"];
Using the ASIHTTPRequest Framework
http://allseeing-i.com/ASIHTTPRequest/

Last edited by YoseMite; 03-08-2010 at 05:29 AM.
YoseMite is offline   Reply With Quote
Old 03-09-2010, 03:37 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Hong Kong, China
Posts: 19
Default

First for all, thx a lot

But i still have some question.

- Which one framework for ASIFormDataRequest should i import?
I cannot find out the framework.

- And can i use the NSURLRequest to develop?

- What are the difference between NSURLRequest and ASIFormDataRequest?


Many thx =)
ansonyik is offline   Reply With Quote
Old 03-09-2010, 03:38 AM   #4 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Hong Kong, China
Posts: 19
Default

First for all, thx a lot

But i still have some question.

- And can i use the NSURLRequest to develop?

- What are the difference between NSURLRequest and ASIFormDataRequest?


Many thx =)
ansonyik is offline   Reply With Quote
Old 03-24-2010, 04:01 AM   #5 (permalink)
gems
 
Join Date: Jan 2010
Location: kolhapur
Posts: 23
Red face

Quote:
Originally Posted by ansonyik View Post
I want to pass some data from iPhone to Php. Plz, anyone can help me to solve this problem.
Thx sooooooooooooooo much =)

My situation,

Now, i created the php file(*It can send email from server, and which is work).Then, I used the Interface Builder to created the interface view in my app. So, the user can use the iphone device (*OS 3.0 or above) to input their information (for example: email address, user's name, etc.) and press the "Send" button to send the data to php. But I dont want to open the browser to view the php in iphone directly.

sendEmail.php variable
$name = $_POST['firstName'];
$email = $_POST['emailAddress'];

Sir,
I am dealing with the same problem. i have my app including some text boxes and on one click i want to store the data inputted in textfields to the PHP file present at server side
any help
Mahesh
gems is offline   Reply With Quote
Old 03-24-2010, 04:52 AM   #6 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Default

Hi there!

I'm working in an application that uses .php files stored in a server. In the iPhone app user have to enter it's username and password, then send it to the server (without using Safari) and then the server returns some information in .xml format (which is received and stored by the app). This is how username and password are sent:

Code:
// check if textFields aren't empty
if (![self.txtName.text isEqualToString:@""] && ![self.txtPass.text isEqualToString:@""]) {
		NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://www.yourweb.com/yourfile.php?user=%@&pass=%@",self.txtName.text,self.txtPass.text]];
		
		NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
		
		NSData *urlData;
		NSURLResponse *response;
		urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
                // urlData receives the returned information and then you can process
                // it by storing in a temporary file and working with NSStrings
Hope it helped!
Johanovski is offline   Reply With Quote
Old 03-30-2010, 10:11 AM   #7 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 1
Question wont work for me....

Quote:
Originally Posted by Johanovski View Post
Hi there!

I'm working in an application that uses .php files stored in a server. In the iPhone app user have to enter it's username and password, then send it to the server (without using Safari) and then the server returns some information in .xml format (which is received and stored by the app). This is how username and password are sent:

Code:
// check if textFields aren't empty
if (![self.txtName.text isEqualToString:@""] && ![self.txtPass.text isEqualToString:@""]) {
		NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://www.yourweb.com/yourfile.php?user=%@&pass=%@",self.txtName.text,self.txtPass.text]];
		
		NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
		
		NSData *urlData;
		NSURLResponse *response;
		urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
                // urlData receives the returned information and then you can process
                // it by storing in a temporary file and working with NSStrings
Hope it helped!
hi thanks for your code it helped lots!

how could one adapt this to insert an entry to a database?

in my attempt it creates an empty row in the table.

thanks.
niallduffy1988 is offline   Reply With Quote
Old 04-04-2010, 02:37 PM   #8 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 6
Default

Your php code is looking for POST data while the NSURL code above is a GET request. You have to use POST as follows :-
[NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:<your php url>];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:@"var1=val1&var2=val2"]; //Replace with your actual name/parm values
[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];

Last edited by bearbully; 04-04-2010 at 02:44 PM.
bearbully is offline   Reply With Quote
Old 03-16-2011, 08:49 AM   #9 (permalink)
Mishti
 
Join Date: Mar 2011
Location: Mumbai
Posts: 28
Default How to send/pass the data from iPhone to php?

Quote:
Originally Posted by gems View Post
Sir,
I am dealing with the same problem. i have my app including some text boxes and on one click i want to store the data inputted in textfields to the PHP file present at server side
any help
Mahesh
u can give me ur mail id i send useful code..
mishti is offline   Reply With Quote
Old 03-16-2011, 10:20 AM   #10 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 6
Default

The code snippet I put in my earlier comments should help you.
bearbully is offline   Reply With Quote
Old 08-10-2011, 05:21 PM   #11 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 1
Default Hey mishti

hey mishti, could you send me the useful code you talked about as I need to send post request from my iPhone app to the web server in php.

thank you for your help
SalehAlmusallam is offline   Reply With Quote
Reply

Bookmarks

Tags
email, interface builder, iphone, php, send data

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,884
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, karlam963
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:12 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0