Answer the question
In order to leave comments, you need to log in
Why is json written incorrectly?
This is how I set the variables
$content = ["$emailr" => "$passwordr"];
$contentJson = json_encode($content);
file_put_contents($filename,$contentJson, FILE_APPEND );
{
"[email protected]": "123Qwe123",
"[email protected]":"Qwe123Qwe"
}
{
"[email protected]": "123Qwe123",
"[email protected]":"Qwe123Qwe"
}{"[email protected]":"123Qwe123"}
Answer the question
In order to leave comments, you need to log in
Everything is right for you. Exactly what you wrote and no magic. You create a json string, you write it to the end of the file, and that's it. You are not adding new data to the json string that is in the file. You just write a string to the file: {...}{...}{...}{...}...
You need to redo your code, first read the file, then convert the data to json, add your data there , convert back to a string, and overwrite the file.
$json = file_get_contents($filename);
$array = json_decode($json);
$array[$emailr] = $passwordr;
file_put_contents($filename, json_encode($array));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question