Hi All,
I was following a tutorial online that showed how to imput info into a MySQL database from an app, and I decided to edit it a little so that I could post what I wanted as opposed to the provided example. The problem im having is that the app itself does work, however when I fill out both text fields and click the send button, the data in the textfields does NOT show up in the mySQL database.

Here is my php file:


$username = "root";
$database = "login"; //name of database
$password = "*****"; //not telling

mysql_connect(xx.xxx.xxx.xxx:3306, $username, $password);  //The IP is right 

@mysql_select_db($database) or die("Unable to find database");

$name = $_GET["Name"];

$userID = $_GET["User_ID"];

$query = "INSERT INTO Login VALUES ('$name','$userID')";

mysql_query($query) or die(mysql_error("error"));



here is my page.h file:

#import <UIKit/UIKit.h>
#define kPostURL @"xx.xxx.xxx.xxx:3306/signup.php" //change ip here
#define kName @"name"
#define kUser @"user"

@interface SignupPage : UIViewController{
    IBOutlet UITextField *nameText;
    IBOutlet UITextField *userID;
    NSURLConnection *postConnection;


- (IBAction)backgroundTouched:(id)sender;
- (IBAction)post:(id)sender;


Here is my page.m file:

#import "SignupPage.h"

@implementation SignupPage

    [nameText resignFirstResponder];
    [userID resignFirstResponder];


-(void) postMessage: (NSString*) user withName: (NSString *) name{

    if(name != nil && user != nil) {

        NSMutableString *postString = [NSMutableString stringWithString: kPostURL];

        [postString appendString: [NSString stringWithFormat:@"?%@=%@", kName, name]];
        [postString appendString: [NSString stringWithFormat:@"%@=%@", kUser, user]];
        [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];




    [userID resignFirstResponder];



    [self postMessage:userID.text withName:nameText.text];
    [userID resignFirstResponder];
    userID.text = nil;
    nameText.text = nil;
    [self dismissViewControllerAnimated:YES completion:NULL];


any idea whats wrong? thanks in advance!

Recommended Answers

If you call your PHP script manually, does it work (inserts into the database)?

Jump to Post

If you go to http://x.x.x.x/signup.php?Name=you&User_ID=1 does it get added to the database?

Jump to Post

If it downloads the file, then PHP is not installed (correctly).

Jump to Post

All 10 Replies

If you call your PHP script manually, does it work (inserts into the database)?

im a bit new to this, so im not sure how to manually call it. I know that if I type in the Ip and go into the signup.php file through my browser, I dont get an error however.

If I dont add :3306 at the end of the ip, it wont connect. When I do however, it downloads the PHP file to my computer, and doesnt add the information to the database.

If it downloads the file, then PHP is not installed (correctly).

How would I install it correctly?

What are you running, Apache or IIS?

apache, and im using Xampp for the mysql server if that makes a difference.

Not too familiar with Xampp. Is it running?

es xampp is running, and php and mysql are online. I can also go in and edit the tables/databases without a problem. My guess is that there is an error in the php script or in the actual app code, but if there is I cant find it....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.