Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8810959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:14:44+00:00 2026-06-14T03:14:44+00:00

Like the title says.. My NSDictionary initWithObjectsAndKeys for JSON, with the POST method, to

  • 0

Like the title says..

My NSDictionary initWithObjectsAndKeys for JSON, with the POST method, to do MySQL query via PHP code, by using the json_encoding and json_decoding creates empty data in my SQL database, just the ID int is auto increasing every time I post!

My Xcode code:

-(IBAction)setJsonFromData:(id)sender
{
    NSDictionary *jsonDict = [[NSDictionary alloc] initWithObjectsAndKeys: @"Welcome", @"title", @"Hello", @"article", @"123456789", @"timestamp", nil];

    if([NSJSONSerialization isValidJSONObject:jsonDict])
        {
           NSError *error = nil;
           NSData *result = [NSJSONSerialization dataWithJSONObject:jsonDict     options:NSJSONWritingPrettyPrinted error:&error];
           if (error == nil && result != nil) {
           [self postJSONtoURL:result];
        }
    }
}

-(id)postJSONtoURL:(NSData *)requestJSONdata
{
    NSURL *url = [NSURL URLWithString:@"http://test.com/json.php"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [request setValue:[NSString stringWithFormat:@"%d", [requestJSONdata length]] forHTTPHeaderField:@"Content-Length"];
    [request setHTTPBody: requestJSONdata];

    NSURLResponse *response = nil;
    NSError *error = nil;

    NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

    NSLog(@"RESULT: %@", requestJSONdata);

    if (error == nil)
        return result;
    return nil;
}

My PHP code:

if (isset($_REQUEST))
{
    $json = $_REQUEST;
    $data = json_decode($json);

    $title = $_REQUEST['title'];
    $article = $_REQUEST['article'];
    $timestamp = $_REQUEST['timestamp'];

    mysql_query("INSERT INTO news (title, article, timestamp) VALUES ('$title->title','$article->article','$timestamp->timestamp')");
}

mysql_close();  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:14:45+00:00Added an answer on June 14, 2026 at 3:14 am

    You’re receiving the json payload in the http body since you do a POST request.
    So, you’ll need to decode that:

    $http_body = file_get_contents('php://input');
    $data = json_decode($http_body);
    

    After that you should be able to access data like:

    $data->title
    

    PHP does not automatically decode incoming json data.

    see the docs regarding that php://input thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Like the title says, PHP is really confusing me on a simple if comparison
as the title says, I would like to create a many-to-one relationship using Fluent
Like the title says, I have the following exception: Description: Event code: 3005 Event
Like the title says, my code basically does this: set proxy, test proxy, do
Like the title says: can we use ...USING fts3(tokenizer icu th_TH, ...) . If
Like the title says, I am using devise. I want to navigate to /users/1
Like the title says, I can't get Canvas/CanvasLayer working in PlayN. My sample code
Like the title says, I need to use php (wordwrap or whatever works) to
Like the title says Where and How (i.e. if encrypted, with what method) does
Like the title says, how do you create custom code snippets in Visual Studio

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.