Hello I Have This Php Code:
$Name = $_POST["Name"];
$sobrenome = $_POST["sobrenome"];
$data_time = $_POST["data_time"];
$data = array(
array(
"nome" => $Name,
"sobrenome" => $sobrenome ,
"data" => $data,
),
);
$arquivo = 'form.json';
$json = json_encode($data);
$file = fopen(__DIR__ . '/' . $arquivo,'w');
fwrite($file, $json);
fclose($file);
as you can see it converts my form into an array and saves it in a json file so far so good, but the problem is that if I send the form more than once it subscribes to the current data, how could I create a new array each does it already exist?
edit: here's an example, suppose when i sent the form the first time i put the value in nome: Nicolas and Sobrenome: Baiger and last in data_time i put 18:31, so form.json would look like this:
'[{"nome":"Nicolas", "Sobrenome":"Baiger", data_time:"18:31"}]'
Now if I put in the nome: Jhon in the Sobrenome: Clynton and in data_time: 12:30 and I submit the form a second time it would overwrite all the other data that I had previously put in like this:
'[{"nome":"Jhon", "Sobrenome":"Clynton", data_time:"12:30"}]'