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 9194223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:21:28+00:00 2026-06-17T21:21:28+00:00

I have 4 input, which sent by Ajax 4 data, to a php file:

  • 0

I have 4 input, which sent by Ajax 4 data, to a php file:
how can I load json file and then add new data whih php?

<input type="text" id="name">
<input type="text" id="surname">
<input type="text" id="mobile">
<input type="text" id="email">
<script>
var name = $("#name").val();
var surname = $("#surname").val();
var mobile = $("#mobile").val();
var email = $("#email").val();
$.ajax({type:"POST",
    url:"wjson.php",
    data:"name="+nombre+"&surname="+surname+"&mobile="+mobile+"&email="+email,
    success:function(data) {

    }
});

JSON file: (people.json)

{
    "1":
    {
        "Name" : "Jhon",
        "Surname" : "Kenneth",
        "mobile" : 329129293,
        "email" : "jhon@gmail.com"
    },
    "2":
    {
        "Name" : "Thor",
        "Surname" : "zvalk",
        "mobile" : 349229293,
        "email" : "thor@gmail.com"
    }
}

wjson.php file :

<?php
$nane = $_POST['name'];
$surname =$_POST['surname'];
$mobile = $_POST['mobile'];
$email =$_POST['email'];
$str_datos = file_get_contents("people.json")
//add new data to people.json
?>

by the way people.json file is in my server

  • 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-17T21:21:30+00:00Added an answer on June 17, 2026 at 9:21 pm

    You can do it like this:

    // Loading existing data:
    $json = file_get_contents("people.json");
    $data = json_decode($json, true);
    
    // Adding new data:
    $data[3] = array('Name' => 'Foo', 'Surname' => 'Bar');
    
    // Writing modified data:
    file_put_contents('people.json', json_encode($data, JSON_FORCE_OBJECT));
    

    However, reading and writing a blob of possibly large size just to add a small item or two is not the best idea. If your dataset starts growing, consider alternative solutions.

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

Sidebar

Related Questions

I have 4 input, which sent by Ajax 4 data, to a php file:
I have a streaming input which has repeated values. I can use any data
I have a page where the user sends data (via ajax) to a php
I have a form that you dynamically creates new input fields (type=hidden) which when
I have a form, which sends data through a Jquery Ajax Call over to
I have a form which sent the entered values using ajax: var form_data =
I have a ajax function in index.php which calls on the page thread.php which
I have an input which is about 450 today, and it might increase in
I have an input which gets a statement from the user. According with the
I have an input which is of this form: (((lady-in-water . 1.25) (snake .

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.