I'm creating an app where the user clicks two buttons and it uploads information from that into a external mysql database hosted on godaddy. This code use to work but no longer does, I can't understand why it's now stopped working. Can you see whats wrong with the code? Or if this even the best way to go about doing this In my .h file I have this along with my textfields
#define kPostURL @"http://www.mywebsite.com/dosomething.php"
#define kName @"name"
#define kMessage @"message"
In my .m file I have this code
-(void) postMessage:(NSString*) message withName:(NSString *) name{
//check isnt receiving two anit paramters
if(name !=nil && message !=nil){
NSMutableString *postString = [NSMutableString stringWithString:kPostURL];
[postString appendString:[NSString stringWithFormat:@"?%@=%@",kName, name]];
//makes kname equal to name
[postString appendString:[NSString stringWithFormat:@"&%@=%@", kMessage , message]];
[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)post:(id)sender{
_textField3.text = @"15";
[self postMessage: self.textField2.text withName:self.textField3.text];
_textField2.text = nil;
_textField3.text = nil;
[self dismissViewControllerAnimated:YES completion:nil];
}
Below is my php file, this was working and then I changed it to (int)$_POST["name"],to see what it done and it didn't work I then changed it back to the original $name = $_POST["name"] and it no longer works. It now creates a new test entry but has blank name and message fields, where as before it use to populate it.
<?php
include ("./inc/connect.inc.php");
//header('Content-type: application/json');
$name = $_POST["name"];
$message =$_POST["message"];
$query = "INSERT INTO test VALUES ('','$name','$message')";
mysql_query($query) or die(mysql_error("error"));
mysql_close();
?>
Why has it done this? Is this the correct way to add an entry into a database