0

I would like to store 4 values in my database. longitude,latitude phone number and timestamp.

I got it al figured out how to store them locally with the NSLOG,

But i want to send it to my MySQL database.

Does somebody have some tutorials or want to help me out here?

I need this badly,

Your help would be appreciated.

Greets

UPDATE

Here's some code i need to store in my database

    resultsLabel.text = [NSString stringWithFormat:@"(%@) %@ Location %.06f %.06f %@", ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) ? @"bg" : @"fg", resultsLabel.tag == 0 ? @"gps:" : @"sig" , newLocation.coordinate.latitude, newLocation.coordinate.longitude,  [formatter stringFromDate:newLocation.timestamp]];

LocationTestAppDelegate * appDelegate = (LocationTestAppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate log:resultsLabel.text];

NSString* encodedValue = [newLocation.coordinate.latitude
                          stringByAddingPercentEscapesUsingEncoding:
                          NSASCIIStringEncoding];

//construct an URL for your script, containing the encoded text for parameter value
NSURL* url = [NSURL urlWithString:
              [NSString stringWithFormat:
               @"http://yourdomain.com/locatie.php?id=%@",
               encodedValue]];

NSError* error = nil;
//send the request synchronously, store the response in result
NSString* result = [NSString stringWithContentsOfURL:url
                                            encoding:NSUTF8StringEncoding
                                               error:&error];

if (!error && ([result isEqualToString:@"OK"])) {
    // everything went well
}

And i need to store the phone number from a textfield, longitude, latitude & timestamp.

Greets(again)

2
  • I have tried to do SQLite but until now this doesn't work.. Commented Sep 3, 2012 at 9:36
  • If you post code then people are far more likely to be able to assist in fixing it and helping you out. ;) Commented Sep 3, 2012 at 9:36

3 Answers 3

2

Use the following code

  //Create String
    NSString *var1 =@"waitTime=";
    NSString *var2 =@"&cover=";
    NSString *wait = [var1 stringByAppendingString:waitTime.text];
    NSString *co = [var2 stringByAppendingString:cover.text];


    NSMutableURLRequest *request = 
    [[NSMutableURLRequest alloc] initWithURL:
     [NSURL URLWithString:@"http://mysite.net/index.php"]];

    [request setHTTPMethod:@"POST"];

    NSString *postString = [wait stringByAppendingString:co];

    [request setValue:[NSString 
                       stringWithFormat:@"%d", [postString length]] 
   forHTTPHeaderField:@"Content-length"];

    [request setHTTPBody:[postString 
                          dataUsingEncoding:NSUTF8StringEncoding]];

    [[NSURLConnection alloc] initWithRequest:request delegate:self];

You can get the status code as explained in this link

- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
   NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
   int code = [httpResponse statusCode];
}

Status codes are defined at this link.

Following a POST command, this indicates success, but the textual part of the response line indicates the URI by which the newly created document should be known.

If the connection times out, you should see this when the connection:didFailWithError: delegate method is called.

Use the PHP tutorial to send the POST data (received from iOS) to MYSQL Database via PHP.

Sign up to request clarification or add additional context in comments.

Comments

1

Is this helpful ?

INSERT INTO table_name (column1, column2, column3,...)
 VALUES (value1, value2, value3,...)

1 Comment

Well i need the PHP code and iOs code to implement it in my app
1

Well i am not sure what you want but as i understand in genral if you want to update your local data on the mysql server then u just do simple thing

add ASIHTTPrequest or AF and sbjeson framework and encode ur data into json and send with post or get method to php page where php can decode the dictionary as a associative array and just loop through and update into mysql.

and if u just want to store data then you should use Codedata or sqlite.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.