I have to show a page from my php script based on certain conditions. I have an if condition and am doing an \"include\" if the condition is satisfied.
if(co
Do this:
NSString *lname = [NSString stringWithFormat:@"var=%@",tname.text];
NSString *lpassword = [NSString stringWithFormat:@"var=%@",tpassword.text];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://localhost/Merge/AddClient.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"insert" forHTTPHeaderField:@"METHOD"];
NSString *postString = [NSString stringWithFormat:@"name=%@&password=%@",lname,lpassword];
NSString *clearpost = [postString stringByReplacingOccurrencesOfString:@"var=" withString:@""];
NSLog(@"%@",clearpost);
[request setHTTPBody:[clearpost dataUsingEncoding:NSUTF8StringEncoding]];
[request setValue:clearpost forHTTPHeaderField:@"Content-Length"];
[NSURLConnection connectionWithRequest:request delegate:self];
NSLog(@"%@",request);
And add to your insert.php
file:
$name = $_POST['name'];
$password = $_POST['password'];
$con = mysql_connect('localhost','root','password');
$db = mysql_select_db('sample',$con);
$sql = "INSERT INTO authenticate(name,password) VALUES('$name','$password')";
$res = mysql_query($sql,$con) or die(mysql_error());
if ($res) {
echo "success" ;
} else {
echo "faild";
}