I have a UIBarButtonItem which needs to update a table when clicked, my problem is i'm not sure how to import the username that is logged in, to identify the user that is being updated, I believe I can manage the location portion, essentially checking the location array for a string and setting location variable equal to it.
My username is stored in a different file as
NSString *post = [[NSString alloc] initWithFormat:@"Username=%@&Password=%@", [_username text], [_password text]];
Location is stored here
NSURL * url = [NSURL URLWithString:getDataURL];
NSData * data = [NSData dataWithContentsOfURL:url];
_jsonArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
//Set up location array
_locationArray = [[NSMutableArray alloc] init];
//loop through jsonArray
for (int i=0; i < _jsonArray.count; i++) {
//Create city object
NSString * gName = [[_jsonArray objectAtIndex:i] objectForKey:@"Name"];
NSString * gAddress = [[_jsonArray objectAtIndex:i] objectForKey:@"Address"];
//Add city object to our cities array
[_locationArray addObject:[[Locations alloc] initWithCityName:gName andtheAddress:gAddress]];
My current code
NSString *username = @"username";// username to identify table
/*Not yet sure how to implement location. Something along the lines of
if ([_currentCity.gName isEqualToString:@"name"])*/
NSString *url = [NSString stringWithFormat:@"http://url/checkIn.php"];
// build the request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
NSMutableData *body= [NSMutableData data];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"returned: %@", returnString);
My php file
<?php
$username = $_GET['Username'];
$location = $_GET['Location'];
$con=mysqli_connect("localhost","user","pass","db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "UPDATE users SET Location='$location' WHERE username = '$username'";
mysqli_query($con,$sql);
$result = mysqli_query ($con, "SELECT * FROM users");
mysqli_close($con);
?>