Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6098611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:10:41+00:00 2026-05-23T13:10:41+00:00

I’m trying to build an objective C app which posts data to a remote

  • 0

I’m trying to build an objective C app which posts data to a remote database using ASIHTTPRequest. Currently, I am using MAMP Server and am struggling to get it to work. The php file works when run online, but I am having trouble getting the iphone app to post data to the php file. HEre is my code:

dbconnect.h

#import <Foundation/Foundation.h>


@interface dbconnect : NSObject {

}

-(void) postToDB:(NSString*) msg;

@end

dbconnect.m

#import "dbconnect.h"
#import "ASIFormDataRequest.h"

@implementation dbconnect

-(void) postToDB:(NSString*) msg{
    NSString *myphp = @"/Applications/MAMP/htdocs/databases/test.php";
    NSURL *url = [NSURL URLWithString:myphp];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setPostValue:msg forKey:@"message"];
}

@end

main

#import <UIKit/UIKit.h>
#import "dbconnect.h"

int main(int argc, char *argv[]) {
    dbconnect* dbc;
    dbc = [[dbconnect alloc]init];
    [dbc postToDB:@"TESTING"];
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];    
    int retVal = UIApplicationMain(argc, argv, nil, nil);       
    [pool release]; 
    return retVal;
}

php

<?php

//connect to database
function connect() {
  $dbh = mysql_connect ("localhost", "root", "root") or die ('I cannot connect to the database because: ' . mysql_error());
  mysql_select_db("testers", $dbh); 
  return $dbh;
}

//store posted data
if(isset($_POST['message'])){
  $message = $_POST['message'];
  $dbh = connect();
  $query = "INSERT INTO  messages (message) VALUES ('$message')";
  $result = mysql_query( $query ) or die ("didn't query");  
}
?>

Now I know it is bad practise to change the main method, but I just wanted to build a quick and dirty iphone/php dummy connection to get it working and the main method was the easiest option. Of course in the real app, I will use a view to trigger such actions…

My code compiles and there are no errors, iOSSimulator loads up..but nothing gets posted to my database…

EDIT:

Sorry I did add that but I copied my old version over. It still doesn’t work even when using an asynchronous request, below is the current version of the postToDB function:

@implementation dbconnect

-(void) postToDB:(NSString*) msg{
    NSString *myphp = @"/Applications/MAMP/htdocs/databases/test.php";
    NSURL *url = [NSURL URLWithString:myphp];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setPostValue:msg forKey:@"message"];
    [request startAsynchronous];
}

@end

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:10:41+00:00Added an answer on May 23, 2026 at 1:10 pm

    All else aside, your request is never executed. Make sure to invoke startSynchronous or startAsynchronous on the request object. Please consider reading the “How To use it” guide to ASIHTTPRequest.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.