I have a xcode project in which i need to enter data on button click and then display it in the TableView.
Example: Twitter (follow/unfollow).
1.I click on friend’s icon, a list of my friends appear.
2.When I click on any of my friends, their friends list appear in tableview with follow buttons corresponding to them (mutual friends have unfollow buttons).
3.Now, when I click on the follow button and go back to check my friend list, that particular friend has been added twice.
What I have done so far:
Checked if the sql db exist somewhere else as well.
Checked if the webservice is being called twice.
Everything’s fine. I have iMac and Macbook Pro as well and both of them have same issues.
I have reinstalled Xampp twice but still the same result.
For your reference, following is the php i am using for my Xcode project.
<?php
$id = $_REQUEST['id'];
$fid = $_REQUEST['fId'];
$firstName = $_REQUEST['firstName'];
$lastName = $_REQUEST['lastName'];
$con = mysql_connect("localhost","root","");
if(!$con)
die("Connection failed"."<br/>");
$db = mysql_select_db("db",$con);
if(!$db) die("Database not found!"."<br/>");
$query = "INSERT INTO $id(firstName,lastName,folks_id) VALUES('$firstName','$lastName','$fid')";
print $query;
mysql_query($query,$con);
mysql_close($con);
?>
EDIT: Xcode part for reference
-(IBAction)followButtonClicked:(UIButton *)sender
{
NSMutableString *postString = [NSMutableString stringWithString:kFollowURL];
[postString appendString: [NSString stringWithFormat:@"?%@=%@", kId, [user objectForKey:@"id"] ]];
[postString appendString: [NSString stringWithFormat:@"&%@=%@", kfId, [fId objectForKey:@"fID"] ]];
[postString appendString: [NSString stringWithFormat:@"&%@=%@", kfirstName, [firstNameDict objectForKey:@"firstName"] ]];
[postString appendString: [NSString stringWithFormat:@"&%@=%@", klastName, [lastNameDict objectForKey:@"lastName"] ]];
[postString appendString: [NSString stringWithFormat:@"&%@=%@", kprofileType, [profileTypeDict objectForKey:@"profileType"] ]];
[postString setString: [postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"post string = %@", postString);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]];
[request setHTTPMethod:@"POST"];
followConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
NSLog(@"postconnection: %@", followConnection);
//Get JSON Response from server
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: postString ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
NSLog(@"serverOutput = %@", serverOutput);
}
[SOLVED] The thing which did the trick was that i made fid as unique… so now whenever i click on the follow button, it is entered one and not twice.
Thanx to all of you guys for the help and support.