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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 05-19-2010, 10:41 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 20
lionfly is on a distinguished road
Default How to set up a database and API web page to accept POST updates from iPhone?

Hi there,

I am developing an iPhone app, which now can update Twitter account with GPS coordinates in real-time, by the Twitter API link:
Code:
http://username:password@twitter.com/statuses/update.xml
, and I am looking at how to make my own database to accept updates from iPhone, via a similar API page.

It seems a .php page can serve as the API, and MySQL can serve as the database.

What are the good ways of doing it? Any template code and tutorial please?
lionfly is offline   Reply With Quote
Old 05-20-2010, 08:15 PM   #2 (permalink)
Code before baby wakes up
 
RobotWoods's Avatar
 
Join Date: Sep 2009
Posts: 189
RobotWoods is on a distinguished road
Default

check out w3schools.com, it's a good resource for PHP.

you're going to end up doing something like (here assuming it's just username password):

PHP Code:
<?php
//
here would be your code to connect to the mysql server and db
//
//this takes items sent via POST and makes them easier to cite
$username=$_POST["username"];
$password=$_POST["password"];
//now just do whatever you need to do
$passwordCheck=mysql_query("SELECT password FROM userinfo WHERE username=$username";
$storedPassword=mysql_fetch_row($passwordCheck);
if(
$password==$storedPassword){
//something
}
else{
//something else
}
?>
RobotWoods is offline   Reply With Quote
Old 05-20-2010, 11:08 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Atlanta
Posts: 411
funkytaco is on a distinguished road
Default

What RobotWoods said is basically what you need. But this is not a PHP coding forum. Your questions would be better suited to possibly some other section of this website, or another message board.


- Luis
funkytaco is offline   Reply With Quote
Old 05-27-2010, 11:37 AM   #4 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 20
lionfly is on a distinguished road
Default

Hi Robotwoods,

Thanks for the code.

For sending a Tweet, the "setHTTPBody" is just a single NSString for "status=%@".

For the example php code, how should I code the "setHTTPBody" in the iPhone program to POST into the fields e.g. "$username" and "$password"?

The following code is what I tried:

Code:
NSURL *phpURL=[NSURL URLWithString:@"http://(test web site)/iphoneupdate.php"];
NSMutableURLRequest *phpRequest=[[NSMutableURLRequest alloc] initWithURL:phpURL];
[phpRequest setHTTPMethod:@"POST"];
NSString *sendToPhp=[[NSString alloc] initWithFormat: @"username:%@, password:%@", sendUsername, sendPassword];
[phpRequest setHTTPBody:[sendToPhp dataUsingEncoding:NSASCIIStringEncoding]];
How to specify to POST "sendUsername" to the field "$username", and POST "sendPassword" to the field "$password"?


Thanks a lot!

Gary



Quote:
Originally Posted by RobotWoods View Post
check out w3schools.com, it's a good resource for PHP.

you're going to end up doing something like (here assuming it's just username password):

PHP Code:
<?php
//
here would be your code to connect to the mysql server and db
//
//this takes items sent via POST and makes them easier to cite
$username=$_POST["username"];
$password=$_POST["password"];
//now just do whatever you need to do
$passwordCheck=mysql_query("SELECT password FROM userinfo WHERE username=$username";
$storedPassword=mysql_fetch_row($passwordCheck);
if(
$password==$storedPassword){
//something
}
else{
//something else
}
?>

Last edited by lionfly; 05-27-2010 at 11:49 AM.
lionfly is offline   Reply With Quote
Old 05-28-2010, 10:09 AM   #5 (permalink)
Code before baby wakes up
 
RobotWoods's Avatar
 
Join Date: Sep 2009
Posts: 189
RobotWoods is on a distinguished road
Default

Quote:
Originally Posted by lionfly View Post
For sending a Tweet, the "setHTTPBody" is just a single NSString for "status=%@".

The following code is what I tried:

NSString *sendToPhp=[[NSString alloc] initWithFormat: @"username:%@, password:%@", sendUsername, sendPassword];
You're welcome.

You were almost there:

username=%@&password=%@
RobotWoods is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone-sdk, mysql, php, twitterapi

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
» Online Users: 309
9 members and 300 guests
Abidullah, ajay123123, Fstuff, guusleijsten, HemiMG, newDev, pkIDSF, Sami Gh, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,877
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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