I have 3 values :
- id
- name
I have three UIText field where i can give these input and save these values into a remote database.
I use GET method to accomplish it. And i have no problem. But, if i want to do the same thing with POST method then how can i do that. I think there will be a little change in the current existing code below. Please share with me if any one know the solution. A lot of thanks in advance.
Have a nice day. :)
Code of iOS section :
- (IBAction)saveButton:(id)sender
{
NSString *strURL = [NSString stringWithFormat:@"http://mydomain.com/iOS/Tulon/phpFile.php?name=%@&email=%@", nameTextField.text, emailTextField.text];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSLog(@"strResult %@", strResult);
nameTextField.text = nil;
}
Code of Remote server section :
<?php
/* ----------------------------- Code for Dabase ----------------------------- */
// Database Properties
$dbhost = 'mydomain.com';
$dbuser = 'username';
$dbpass = 'password';
$db = 'dbName';
$dbtable = 'user';
// Connect Database
$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die (mysql_error());
mysql_select_db($db, $conn) or die(mysql_error());
/* ----------------------------- Code for Dabase ----------------------------- */
if (isset ($_GET["name"]) && isset ($_GET["email"]))
{
$name = $_GET["name"];
$email = $_GET["email"];
}
else
{
$name = "Tulon";
$email = "[email protected]";
}
// Insert value into DB
$sql = "INSERT INTO $dbtable (id, name, email) VALUES (NULL, '$name', '$email');";
$res = mysql_query($sql,$conn) or die(mysql_error());
mysql_close($conn);
if ($res)
{
echo "success";
}
else
{
echo "faild";
}
?>