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:
<?php
$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"));
mysql_close();
?>
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)ReturnKeyButton:(id)sender;
- (IBAction)backgroundTouched:(id)sender;
- (IBAction)post:(id)sender;
@end
Here is my page.m file:
#import "SignupPage.h"
@implementation SignupPage
-(IBAction)backgroundTouched:(id)sender
{
[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];
}
}
-(IBAction)ReturnKeyButton:(id)sender{
[userID resignFirstResponder];
}
-(IBAction)post:(id)sender{
[self postMessage:userID.text withName:nameText.text];
[userID resignFirstResponder];
userID.text = nil;
nameText.text = nil;
[self dismissViewControllerAnimated:YES completion:NULL];
}
@end
any idea whats wrong? thanks in advance!