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

  • SEARCH
  • Home
  • 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 8131769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:10:46+00:00 2026-06-06T09:10:46+00:00

I need to update a json list of object via url post data. For

  • 0

I need to update a json list of object via url post data. For example, with url:

http://myweb.com/index.php?name=Peter&surname=Brown

in php, using get method:

$name = $_GET["name"];
$surname = $_GET["surname"];
$json = array();

        $json["nombre"] = $name;
        $json["lat"] = $lat;
        $data[] = $json;

$json_end= json_encode($data);

and json_end efectively is done like I want:

[{"name":"Peter","surname":"Brown"}]

My question is about how I can do it incrementing the json, in order to build an array like:

[{"name":"Peter","surname":"Brown"}]
[{"name":"newname","surname":"newsurname"}]
// and so on

each time user use the url with new parameters.

Do I need to write to a file, or to database? Any tips will be apreciated.

The idea is to be able that any user can add some dat using url. I tried to store the json to a fiel but the storing is durable only along the current session.

  • 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-06T09:10:48+00:00Added an answer on June 6, 2026 at 9:10 am
    <?
    /* This needs to be at the top of your file, without ANYTHING above it */
    session_start();
    
    /* ... */
    
    if(!array_key_exists('entries', $_SESSION))
    {
        $_SESSION['entries'] = array();
    }
    
    $_SESSION['entries'][] = array("name" => $_GET["name"], "surname" => $_GET["surname"]);
    
    $json_string = json_encode($_SESSION['entries']);
    

    This would produce a single JSON. However I don’t know whether you meant to or not, but your output is a series of separate JSONs. You could do this by replacing the last line above with:

    $json_string = '';
    foreach($_SESSION['entries'] as $entry){ 
        $json_string.= json_encode($entry) . "\n";
    }
    

    You would also probably want a way to reset/empty the array. In which case I’d change the if test from:

    if(!array_key_exists('entries', $_SESSION))
    

    to:

    if(!array_key_exists('entries', $_SESSION) || array_key_exists('reset', $_GET))
    

    Which you could use by visiting

    http://myweb.com/index.php?reset
    

    Edit: If somewhere you add the following code:

    foreach($_SESSION['entries'] as $id=>$entry){ 
        printf("%2d: %s\n", $id, json_encode($entry));
    }
    

    You’ll get a list of the json elements enumerated by their respective keys. For example, it might look like:

     0: "[{\"name\":\"Peter\",\"surname\":\"Brown\"}]"
     1: "[{\"name\":\"newname\",\"surname\":\"newsurname\"}]"
     2: "[{\"name\":\"George\",\"surname\":\"Washington\"}]"
     3: "[{\"name\":\"John\",\"surname\":\"Adams\"}]"
    

    If you then add the following code:

    if(array_key_exists('del', $_GET) && is_numeric($_GET['del']))
    {
        $key = (int)$_GET['del'];
        if(array_key_exists($key, $_SESSION['entries']))
        {
            unset($_SESSION['entries'][$key]);
        }
        else
        {
            printf('<strong>ERROR: $_GET['del'] = %d but $_SESSION['entries'][%d] doesn't exist.</strong>', $key, $key);
        }
    }
    

    you’ll be able to delete individual json entries by specifying id as the del GET parameter.

    For example,

    http://myweb.com/index.php?del=2
    

    would delete the entry corresponding to '[{"name":"George","surname":"Washington"}]';

    And the remaining entries would be:

     0: "[{\"name\":\"Peter\",\"surname\":\"Brown\"}]"
     1: "[{\"name\":\"newname\",\"surname\":\"newsurname\"}]"
     3: "[{\"name\":\"John\",\"surname\":\"Adams\"}]"
     4: "[{\"name\":\"Thomas\",\"surname\":\"Jefferson\"}]"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to POST a JSON String containing a List of 1 or more
I have a JSON object with an array of updates, where each update consists
I have JSON object : { _id : 1, _class : com.model.Test, projectList :
I need to update an existing SharePoint content type by adding a new field
I need to update the primary key for a record but it's also the
I need to update a record in the datastore, but instead of updated record
I need to update jquery1.3.2 to jquery1.4 (in Asp.net MVC). Please can anyone tell
I need to update two tables inside a single transaction. The individual queries look
I need to update a lot of rows, per a user request. It is
I need to update a field (called updated_at ). The field in MySQL is

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.